Is there an "inline-equivalent" to expressions like the following?:
if [[ $VERBOSE == 1 ]]; then
V=$FOO
else
V=
fi
I'm thinking of something like this in perl
, for example:
$V = $VERBOSE ? $FOO : undef;
(BTW, my interest is not so much in the business of reducing five lines to one, since one could always re-write the shell snippet as
if [[ $VERBOSE == 1 ]]; then V=$FOO; else V=; fi
but rather in a single conditional expression that is equivalent to a multi-statement if
-construct.)
In case there's a difference, I'm interested primarily in the answer for zsh
, but also in the one for bash
.