Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

let's say, I can rsh to machine XXX as user foo, then after executing:

$result=$(rsh -l foo XXX "ls");
echo $result;

I found that the line feed is removed in the result, and I can't see the result in a line by line way. so what I should do if I'd like to have the line feed int the returned result?

share|improve this question
You should not have a dollar sign in front of the varible name when you assign to it. rsh=$(rsh -l foo XXX "ls"). The terminating semicolons are redundant but harmless. – tripleee Mar 12 '12 at 8:05

The newline is there; the error is in using echo to examine it (without double quotes around the variable, too!)

result=$(rsh -l foo XXX "ls")
echo "$result"
share|improve this answer

Edit: If you mean the newlines between each file, just make sure to quote the result:

result="$(rsh -l foo XXX "ls");"

This will keep any characters except NUL ($'\0'), which can't be stored in a Bash variable.

If you mean that the trailing newline is lost, then this is the simplest solution I know:

resultx="$(commands...; echo x)"
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .