make install ${MAKE_PREFIX} ${NO_OUTPUT}
Calls make
with install
, the result of split+glob applied to the contents of the MAKE_PREFIX variable and the result of split+glob applied to the contents of the NO_OUTPUT variable as separate arguments.
Probably you want something like:
if [ -n "$VERBOSE" ]; then
nooutput() { "$@"; }
else
nooutput() { "$@" > /dev/null 2>&1; }
fi
nooutput make install "$MAKE_PREFIX"
For make
to be called with install
and the contents of the MAKE_PREFIX variable as separate arguments, and its stdout and stderr redirected to /dev/null if not run in verbose mode.
You could also use aliases here:
if [ -n "$VERBOSE" ]; then
alias nooutput=' '
else
alias nooutput='> /dev/null 2>&1 '
fi
nooutput make install "$MAKE_PREFIX"
Though beware if using the bash
shell not in POSIX mode, you need shopt -s expand_aliases
.
The alias also needs to have been defined at the time the code using it was read (not run).
In zsh
, you can also have global aliases that are expanded even when not in command position, so you could do:
if [ -n "$VERBOSE" ]; then
alias -g '$NOOUTPUT$='
else
alias -g '$NOOUTPUT$=> /dev/null 2>&1'
fi
make install "$MAKE_PREFIX" $NOOUTPUT$
Here using $NOOUTPUT$
instead of $NOOUTPUT
to make it clearer that no parameter expansion is happening there, the $NOOUTPUT$
is being replaced with either nothing or > /dev/null 2>&1
when the code is being read, long before it is being evaluated.
eval 'make install "$MAKE_PREFIX" '"$NO_OUTPUT"
. i.e., you don't want the expansion of$MAKE_PREFIX
to be passed toeval
, and you don't want either of these variables to be subject to split+glob. You wanteval
to evaluated themake install "$MAKE_PREFIX" > /dev/null 2>&1
shell code. – Stéphane Chazelas Sep 07 '22 at 08:39