[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: `...` v. $(...) (was: wget and captcha puzzle !!!)



On Sat, Jan 21, 2012 at 10:43:20AM -0700, Bob Proulx wrote:
> Tony Baldwin wrote:
> > John Hasler wrote:
> > > Bob writes:
> > Sort of OT, but mentioned in this thread,
> > Why use $(command) instead of `command`?
> > Generally, I've always used $(command), but see scripts all over using
> > `command`, and wondered if there were advantages of one over the other.
> > It seems they give the same result, no?
> 
> The `...` is the original Bourne shell syntax for executing a command
> and replacing the output from it onto the command line.  It is the
> oldest method and in the simple case works everywhere.  However the
> quoting rules are difficult.  Quoting includes both double and single
> quotes and also includes nested `...` statements within `...`
> statements.  There is always a quoting solution but it can be tedious
> to create correctly.
> 
> The $(...) is newer syntax from ksh (newer from 1986 or so) which was
> standardized into POSIX and therefore all POSIX shells will support
> it.  The use of matching parenthesis means that nesting of commands is
> simpler.  Most importantly the quoting rules are regular throughout.
> You can even nest $(...)  inside of $(...).  For example: $(...  $(...) )
> 
> The simpler and regular quoting rules wins the choice for me.
> 
> Bob
Thanks for this thorough and enlightening explanation.

./tony

-- 
http://www.tonybaldwin.me
all tony, all the time!


Reply to: