help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Evaluations of backticks in if statements


From: Andy Chu
Subject: Re: [Help-bash] Evaluations of backticks in if statements
Date: Thu, 23 Feb 2017 09:45:32 -0800

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]