Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15174

backquote peculiarities (was: Re: Combination of "eval set -- ..." and $() command substitution is slow)

From astian <astian@e-nautia.com>
Newsgroups gnu.bash.bug
Subject backquote peculiarities (was: Re: Combination of "eval set -- ..." and $() command substitution is slow)
Date 2019-07-15 22:19 +0000
Message-ID <mailman.1472.1563229198.2688.bug-bash@gnu.org> (permalink)
References <bcd08f6c-1c13-0eb4-92b2-4e904b19a0ce@e-nautia.com> <8091.1563212947@jinx.noi.kre.to> <84005319-e232-8404-fe0b-471dafad381c@e-nautia.com>

Show all headers | View raw


Robert Elz:
>     Date:        Wed, 10 Jul 2019 17:21:00 +0000
>     From:        astian <astian@e-nautia.com>
>     Message-ID:  <bcd08f6c-1c13-0eb4-92b2-4e904b19a0ce@e-nautia.com>
> 
> I doubt it makes any difference to the timing, which I think
> Chet has already answered, but it is worth pointing out that these
> two commands ...
> 
> 			printf '%s\n' "`printf %s "$i"`"
> 			printf '%s\n' "$(printf %s "$i")"
> 
> which (I believe)) are supposed to be the same thing, using the
> different (ancient, and modern) forms of command substitution aren't
> actually the same.   In the first $i is unquoted, in the second it is
> quoted.   Here, since its value is just a number and IFS isn't being
> fiddled, there is not likely to be any effect, but if you really
> want to make those two the same, the first needs to be written as
> 
> 			printf '%s\n' "`printf %s \"$i\"`"
> 
> Such are the joys of `` command substitutions (just avoid them).
> 
> kre

Dear Robert Elz, I'm aware of several of its peculiarities and I typically do
avoid them.  However, is it true that $i is unquoted in the first case?
Consider:

  i='foo bar'
  set -x
  printf '%s\n' "`printf '<%s>' "$i"`"
  printf '%s\n' "`printf '<%s>' \"$i\"`"
  printf '%s\n' "`printf '<%s>' $i`"

Which outputs:

  ++ printf '<%s>' 'foo bar'
  + printf '%s\n' '<foo bar>'
  <foo bar>
  ++ printf '<%s>' 'foo bar'
  + printf '%s\n' '<foo bar>'
  <foo bar>
  ++ printf '<%s>' foo bar
  + printf '%s\n' '<foo><bar>'
  <foo><bar>

Cheers.

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

backquote peculiarities (was: Re: Combination of "eval set -- ..." and $() command substitution is slow) astian <astian@e-nautia.com> - 2019-07-15 22:19 +0000

csiph-web