Consider the following commands:
What is displayed when this sequence of commands is executed using the bash shell?
A.
Hello, world
B.
cat: cannot open file1
C.
cat: cannot open file1Hello, world
D.
cat: cannot open file1 Hello, World
E.
bash: syntax error near unexpected token ‘&&’
Explanation:
First line (rm file1) deletes/removes file1.
Second line captures the text into file2.
The first part of line 3 (cat file1) fails as the file1 does not exist.
The && (AND) operator will ensure that the third line fails. The result of line 3 will be the result of first part of line
3 (cat file1).
Note: cat – concatenate files and print on the standard output
Note #1: A list is a sequence of one or more pipelines separated by one of the operators ‘;’, ‘&’, ‘&&’, or ‘||’, and
optionally terminated by one of ‘;’, ‘&’, or a newline.
Of these list operators, ‘&&’ and ‘||’ have equal precedence, followed by ‘;’ and ‘&’, which have equal
precedence.
AND and OR lists are sequences of one or more pipelines separated by the control operators ‘&&’ and ‘||’,
respectively. AND and OR lists are executed with left associativity.
An AND list has the form
command1 && command2
command2 is executed if, and only if, command1 returns an exit status of zero.
An OR list has the form
command1 || command2
command2 is executed if, and only if, command1 returns a non-zero exit status.
The return status of AND and OR lists is the exit status of the last command executed in the list.
Note #2 (on exit status): Zero means command executed successfully, if exit status returns non-zero value then
your command failed to execute.