Bash script variables question[Scanned]

Cameron Simpson cs at zip.com.au
Sun Aug 6 22:21:14 UTC 2006


On 06Aug2006 13:27, Tom Diehl <tdiehl at rogueind.com> wrote:
| >=>Also, just for other scripts, this:
| >=>	foo=`command`
| >=>is more portable than
| >=>	foo=$(command)
| >
| >Never use backquotes when the $( cmd ) is available.

Portable practice presumes $() not to be available.

| The backquotes are
| >deprecated in bash and ksh and are only available in antique Bourne
| >shells. In addition there are subtle differences in quoting between the
| >two.
| 
| Any idea why the authors feel the need to break 20+ years of history? I 
| fail to
| see why foo=`command` is better or worse than foo=$(command). I only have 
| 17+ years worth of sh, ksh, and bash scripts that use the foo=`command` 
| construct.

There's nothing subtle about it. $(...) lets you nest things without quoting
difficulties. The `...` syntax imposes a layer of slosh quoting. $() is
definitely cleaner and easier. But plenty of platforms exist where it is not
supported in /bin/sh. So $() is to be avoided for portable scripts
on the whole.
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

Because of its special customs, crossposting between alt.peeves and normal
newsgroups is discouraged.      - Cameron Spitzer




More information about the fedora-list mailing list