sh echo ???

sh -c "echo '111 $USER\n$USER'"

output:
Code:
111 root\nroot

\n - I guess this is new line
 
Last edited by a moderator:
You will need to tell echo to expand backslash escapes
Code:
sh -c "echo -e '111 $USER\n$USER'"
yes. you're right. sh(1)

Code:
     echo [-e | -n] [string ...]
             Print a space-separated list of the arguments to the standard
             output and append a newline character.

             -n      Suppress the output of the trailing newline.

             -e      Process C-style backslash escape sequences.
 
Last edited by a moderator:
echo (and input to echo from a commandline reader/shell) is shell specific. you can google up a list of ways "echo" differs in shells. you'd like to avoid shell coding relying on "behaviors"
 
If you want wide portability, it's best to avoid the fancy features of echo, but life is too difficult without a universal way to do BSD "echo -n":
Code:
# BSD "echo -n"
case `echo -n` in
    -*) Echon() { echo ${1:+"$@"}"\c"; };;
    *)  Echon() { echo -n ${1:+"$@"}; };;
esac
 
Back
Top