sh echo ???

bvgdas

New Member

Reaction score: 1
Messages: 10

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

output:
Code:
111 root\nroot

\n - I guess this is new line
 
Last edited by a moderator:

monwarez

Active Member

Reaction score: 75
Messages: 165

You will need to tell echo to expand backslash escapes
Code:
sh -c "echo -e '111 $USER\n$USER'"
 
OP
B

bvgdas

New Member

Reaction score: 1
Messages: 10

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:

eurohick2

New Member


Messages: 8

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"
 

gpw928

Aspiring Daemon

Reaction score: 298
Messages: 645

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
 
Top