分号在 bash 命令中运行时有什么作用? [英] What does the semicolon do when it is run in a bash command?

查看:21
本文介绍了分号在 bash 命令中运行时有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如运行时

echo a; echo b

在终端中,它的输出是:

in the terminal, its output is:

a
b

在我看来,分号等待第一个命令 (echo a) 完成,然后启动第二个命令 (echo 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).

问:分号是否只是用于在 bash 中迭代命令?

Q: Is the semicolon just used for iterating over commands in bash?

问:分号在 bash 命令中运行时的作用是什么?

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

推荐答案

; 将两个命令分开.

echo a; echo b

它让 bash 知道 echo aecho 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

尝试不使用分号

$ echo a echo b
a echo b

这里的语句被当作单个命令 echo 并且 a echo b 作为参数传递给 echo

Here the statement is taken as a single command echo and a echo b is passed as parameter to the echo

这篇关于分号在 bash 命令中运行时有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆