[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Evaluations of backticks in if statements
From: |
Ryan Marples |
Subject: |
Re: [Help-bash] Evaluations of backticks in if statements |
Date: |
Wed, 8 Mar 2017 00:49:26 +0000 |
Sorry for the long delay, was pulled off onto other things. Andy – I’m not
100% clear what your conclusion was. Taking Seth’s example earlier in the
thread:
> $ if `true`; then echo foo; fi
> foo
> $ if `false`; then echo foo; fi
> $
Can you walk me through the explanation of the result of these two command
variations please?
From: Andy Chu <address@hidden>
Date: Thursday, February 23, 2017 at 9:45 AM
To: Seth David Schoen <address@hidden>
Cc: Ryan Marples <address@hidden>, "address@hidden" <address@hidden>
Subject: Re: [Help-bash] Evaluations of backticks in if statements
OK, there is no special case. This is because of what I think of as "empty
unquoted word elision" (not sure if there is a better name).
`true` is not quoted so it doesn't result in an empty string in argv, it
results in NOTHING in argv (empty argv).
Compare:
$ if `true`; then echo TRUE; else echo FALSE; fi
TRUE
$ if "`true`"; then echo TRUE; else echo FALSE; fi
: command not found
FALSE
# passing argument -- ZZZ is the command name, not empty string
$ if `true` ZZZ; then echo TRUE; else echo FALSE; fi
ZZZ: command not found
FALSE
# now it has output, but this isn't a special case either
$ if `sh -c 'echo YYY; true'`; then echo TRUE; else echo FALSE; fi
YYY: command not found
FALSE
This is just like how variables are elided if empty and quoted:
$ empty=; python -c 'import sys; print sys.argv[1:]' a $empty b
['a', 'b']
$ empty=; python -c 'import sys; print sys.argv[1:]' a "$empty" b
['a', '', 'b']
Andy
- Re: [Help-bash] Evaluations of backticks in if statements,
Ryan Marples <=