Skip to main content
Post Undeleted by terdon
Post Deleted by adonis
added 68 characters in body
Source Link
adonis
  • 1.7k
  • 10
  • 9

according to bash manual the order of shell expansions is brace expansion, tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, word splitting, and pathname expansion. also it is stated that the redirections happen before the command is executes - i.e. after shell expansion. Thus it comes to reason that commands like:

redir='>'
echo value $redir file

and

echo value $(echo '>') file

would put value in the file file.

Unfortunately this is not the case because the command line is firstly parsed and the redirection tokens are only identified at this stage. Later, before the command is executed, the redirections are performed based on those tokens.

eval curl $BLAH $( $IS_VERBOSE && echo '-i' || echo '> /dev/null' )

works by re-parsing the command, thus identifies the redirections, but it also performs shell's expansion, which is a bit tricky to work with, and may lead in unexpected behavior.

note: there is special handling in bash for >$var and >&$var

according to bash manual the order of shell expansions is brace expansion, tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, word splitting, and pathname expansion. also it is stated that the redirections happen before the command is executes - i.e. after shell expansion. Thus it comes to reason that commands like:

redir='>'
echo value $redir file

and

echo value $(echo '>') file

would put value in the file file.

Unfortunately this is not the case because the command line is firstly parsed and the redirection tokens are only identified at this stage. Later, before the command is executed, the redirections are performed based on those tokens.

eval curl $BLAH $( $IS_VERBOSE && echo '-i' || echo '> /dev/null' )

works by re-parsing the command, thus identifies the redirections, but it also performs shell's expansion, which is a bit tricky to work with, and may lead in unexpected behavior.

according to bash manual the order of shell expansions is brace expansion, tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, word splitting, and pathname expansion. also it is stated that the redirections happen before the command is executes - i.e. after shell expansion. Thus it comes to reason that commands like:

redir='>'
echo value $redir file

and

echo value $(echo '>') file

would put value in the file file.

Unfortunately this is not the case because the command line is firstly parsed and the redirection tokens are only identified at this stage. Later, before the command is executed, the redirections are performed based on those tokens.

eval curl $BLAH $( $IS_VERBOSE && echo '-i' || echo '> /dev/null' )

works by re-parsing the command, thus identifies the redirections, but it also performs shell's expansion, which is a bit tricky to work with, and may lead in unexpected behavior.

note: there is special handling in bash for >$var and >&$var

Source Link
adonis
  • 1.7k
  • 10
  • 9

according to bash manual the order of shell expansions is brace expansion, tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, word splitting, and pathname expansion. also it is stated that the redirections happen before the command is executes - i.e. after shell expansion. Thus it comes to reason that commands like:

redir='>'
echo value $redir file

and

echo value $(echo '>') file

would put value in the file file.

Unfortunately this is not the case because the command line is firstly parsed and the redirection tokens are only identified at this stage. Later, before the command is executed, the redirections are performed based on those tokens.

eval curl $BLAH $( $IS_VERBOSE && echo '-i' || echo '> /dev/null' )

works by re-parsing the command, thus identifies the redirections, but it also performs shell's expansion, which is a bit tricky to work with, and may lead in unexpected behavior.