[olug] sed issues inside of a script

John Hobbs john at velvetcache.org
Tue Nov 13 20:39:32 UTC 2007


Thanks for all the replies, makes sense now that I've had it spelled
out for me :)

Also, thanks Luke-Jr.  I was playing with that and I never knew you
could do substitutions on a string by treating it as an array like
that.  Very cool.

Thanks again!

- John

On 11/13/07, Obi-Wan <obiwan at jedi.com> wrote:
> >> 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
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> http://lists.olug.org/mailman/listinfo/olug
>



More information about the OLUG mailing list