Issue
I found this statement while I was reading the POSIX documentation Shell and Utilites volume, section 2.1:
The shell performs redirection (see Redirection) and removes redirection operators and
their operands from the parameter list.
Also, I found very similar statement from GNU bash reference manual, section 3.1.1:
Performs any necessary redirections (see Redirections) and removes the redirection
operators and their operands from the argument list.
What is a "parameter list" or "argument list" here?
Solution
It means that they're removed from the list of things that'll be passed to the command as arguments. For example, in this:
somecommand foo bar baz < inputfile.txt > output.log 2>&1
The redirects, < inputfile.txt
, > output.log
, and 2>&1
, get removed from the list of arguments, so it will execute somecommand
with only three arguments: "foo", "bar", and "baz".
Note that this applies even if the redirects are mixed in with the arguments (or even if they're before the command!). So all of these are equivalent to the first example:
somecommand < inputfile.txt foo > output.log bar 2>&1 baz
somecommand < inputfile.txt > output.log 2>&1 foo bar baz
< inputfile.txt > output.log 2>&1 somecommand foo bar baz
(But the order within the argument argument list does matter, and so can the order of the redirects. In this case, putting 2>&1
before > output.log
will change what gets redirected where, and probably not in the way you want. )
Answered By - Gordon Davisson Answer Checked By - Terry (WPSolving Volunteer)