[olug] sed issues inside of a script
Obi-Wan
obiwan at jedi.com
Tue Nov 13 15:05:27 UTC 2007
>> Also, using backticks is deprecated, so best practice would be to use $() in
>> any new scripts that you write.
>
> IIRC, $() is a bashism and will not work in standard sh
That's correct. Better practice is to fully understand the shell in
which you're working. From the sh(1) man page on an older Solaris box:
Command Substitution
The shell reads commands from the string between two grave
accents (``) and the standard output from these commands may
be used as all or part of a word. Trailing newlines from the
standard output are removed.
No interpretation is done on the string before the string is
read, except to remove backslashes (\) used to escape other
characters. Backslashes may be used to escape a grave accent
(`) or another backslash (\) and are removed before the com-
mand string is read. Escaping grave accents allows nested
command substitution. If the command substitution lies
within a pair of double quotes (" ...` ...` ... "), a
backslash used to escape a double quote (\") will be
removed; otherwise, it will be left intact.
If a backslash is used to escape a newline character (\new-
line), both the backslash and the newline are removed (see
the later section on Quoting). In addition, backslashes used
to escape dollar signs (\$) are removed. Since no parameter
substitution is done on the command string before it is
read, inserting a backslash to escape a dollar sign has no
effect. Backslashes that precede characters other than \, `,
", newline, and $ are left intact when the command string is
read.
--
Ben "Obi-Wan" Hollingsworth obiwan at jedi.com
The stuff of earth competes for the allegiance I owe only to the
Giver of all good things, so if I stand, let me stand on the
promise that You will pull me through. -- Rich Mullins
More information about the OLUG
mailing list