I am using Red Hat Linux Enterprise version 5. I’ve noticed people sometimes running commands with a couple of
&
options. For example, in the below command, there are two&
signs. What is the purpose of them? Are they always used together with nohup?nohup foo.sh <script parameters> >& <log_file_name> &
Solution:
In addition to Martin’s, Ash’s and Kevin’s answers, sometimes you’ll see an ampersand used mathematically for a bitwise AND*:
$ echo $(( 11 & 7 ))3
In case you’re not familiar with bit operators:
11: 1011 7: 0111-------- AND 3: 0011
In each position there’s a one bit in the first number AND the second number, set that bit to one in the answer.
*The feature in Kevin’s answer is referred to as a logical AND.
To elaborate on Ash’s answer, when used in redirection the ampersand can tell the shell to copy a file descriptor. In this command echo "hello" > outputfile 2>&1
the ampersand causes any output that may go to standard error (stderr, file descriptor 2) to go to the same place as standard output (stdout, file descriptor 1, the default for the left side of >
). The >& outputfile
operator is shorthand for > outputfile 2>&1
.
Also, new in Bash 4, there are two new terminators for clauses in the case
command ;&
and ;;&
which affect whether a case “falls through” and, if so, whether the next test is performed.