hi,
i can see in a script
it contains
var=$(
myFile | grep -i err
)
why has this person done it like this? why not just
var=`myFile | grep -i err`
thanks
hi,
i can see in a script
it contains
var=$(
myFile | grep -i err
)
why has this person done it like this? why not just
var=`myFile | grep -i err`
thanks
Well, '`' is small (hard to see/discern from "'"), vi '%' does not pair them, and it
does not nest. I am not sure if it swallows linefeeds -- probably. So, good style is to use ksh and $(). Also, use closed paren pairs in 'case' so they stay in balance for vi '%'.
backtick ``
means pass the result as a variable in old fashion
Using $()
is new fashion (some shell implementation may not support this way to write things
thanks guys
Yes, $() is not supported in bourne shell (sh).
Solaris' /bin/sh is one shell in a current OS that keeps popping up that does not support $() . But you can use /usr/xpg4/bin/sh instead ...
Note that, at least as far as ksh93 is concerned, there is a subtle difference between command substitution using $(...) and command substitution using `...`. In the second (obsolute) form, the string between the quotes is processed for special quoting characters before the command is substituted.
I totally agree backticks are terrible, but they do nest, you just have to escape them.
echo $( echo $( echo hallo ) )
echo ` echo \` echo hallo \` `
Multiple nesting is quickly getting insane with backquotes:
echo $(echo $(echo $(echo $(echo $(echo hallo)))))
vs
echo `echo \`echo \\\`echo \\\\\\\`echo \\\\\\\\\\\\\\\`echo hallo \\\\\\\\\\\\\\\` \\\\\\\` \\\` \` `
Reminds me of waterloo fred, an editor with buffers of commands but in buffers all command had to have doubled escapes, . . . That way madless lies.