What does the semicolon do when it is run in a bash command?

不羁岁月 提交于 2020-04-05 05:01:55

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!