问题
For example, when running
echo a; echo b
in the terminal, its output is:
a
b
It seems to me that the semicolon waits for the first command (echo a
) to finish, then it starts the second command (echo b
).
Q: Is the semicolon just used for iterating over commands in bash?
Q: What does the semicolon do when it is run in a bash command?
回答1:
The ;
separates the two commands.
echo a; echo b
It lets the bash know that echo a
and echo b
are two separate commands and need to be run separately one after the other
Try without semicolons
$ echo a echo b
a echo b
Here the statement is taken as a single command echo
and a echo b
is passed as parameter to the echo
回答2:
It's a statement separator. You could also try
sleep 1; echo a
which will wait one second and then display a. As would
sleep 1 && echo a
回答3:
it's a way to simulate a newline.
echo a; echo b
is equivalent to
echo a
echo b
来源:https://stackoverflow.com/questions/27577478/what-does-the-semicolon-do-when-it-is-run-in-a-bash-command