Precedence of logical operators versus semicolon
Yes, and you can easily check it yourself:
$ non-existent-command && echo hi ; echo after semicolon
bash: non-existent-command: command not found
after semicolon
In man bash
it says:
Commands separated by a ; are executed sequentially; the shell waits for each command to terminate in turn.
commandC
will be executed no matter if commandA
or commandB
fails or succeeds.
Semicolon is just a separator to make commands execute sequentially. The only scenario that I can see where commandC
will fail, is if commandA
or commandB
are exit
commands (or any command like return
/break
/continue
/exec
(or functions that call those) that forcefully affects the work flow):
Scenario 1: commandA
is exit
[root@host ~]# exit && echo "HI"; echo "test"
logout
[user@host ~]$
Scenario 2: commandB
is exit
[root@host~]# echo "HI" && exit; echo "test"
HI
logout
[user@host ~]$
tl;dr: Is not that those characters have a precedence. They mean different things. One is a logical operator and the other is a list terminator.
Related Stuff:
What are the shell's control and redirection operators? This answer gives a good explanation about the bash operators. Quoting a little piece of the answer:
;
: Will run one command after another has finished, irrespective of the outcome of the first.command1 ; command2
First
command1
is run, in the foreground, and once it has finished,command2
will be run.A newline that isn't in a string literal or after certain keywords is not equivalent to the semicolon operator. A list of
;
delimited simple commands is still a list - as in the shell's parser must still continue to read in the simple commands that follow a;
delimited simple command before executing, whereas a newline can delimit an entire command list - or list of lists. The difference is subtle, but complicated: given the shell has no previous imperative for reading in data following a newline, the newline marks a point where the shell can begin to evaluate the simple commands it has already read in, whereas a;
semi-colon does not.
Semicolons superfluous at the end of a line in shell scripts? Quoting the answer:
Single semicolons at the end of a line are superfluous, since the newline is also a command separator.
case
specifically needs double semicolons at the end of the last command in each pattern block; seehelp case
for details.What's the difference between semicolon and double ampersand &&