官术网_书友最值得收藏!

  • Bash Quick Start Guide
  • Tom Ryder
  • 211字
  • 2021-07-23 16:58:57

Running commands in sequence

You can send an interactive command line with more than one simple command in it, separating them with a semicolon, one of several possible control operators. Bash will then execute the commands in sequence, waiting for each simple command to finish before it starts the next one. For example, we could write the following command line and issue it in an interactive Bash session:

$ cd ; ls -a ; mkdir New
Running cd on its own like this, with no directory target argument, is a shortcut to take you to your home directory. It's the same as typing cd ~ or cd -- "$HOME".

For this command line, note that even if one of the commands fails, Bash will still keep running the next command. To demonstrate this, we can write a command line to include a command that we expect to fail, such as the rmdir call here:

$ cd ; rmdir ~/nonexistent ; echo 'Hello'
rmdir: failed to remove '/home/bashuser/nonexistent': No such file or directory
Hello

Note that the echo command still runs, even though the rmdir command before it did not succeed. If you want your set of commands to stop if one of them fails, separating them with semicolons is the wrong choice.

主站蜘蛛池模板: 兖州市| 张家界市| 文成县| 沭阳县| 花莲市| 贡觉县| 手游| 垦利县| 阿尔山市| 凤阳县| 濉溪县| 西华县| 伊川县| 买车| 大荔县| 屯昌县| 图们市| 托克逊县| 普定县| 周宁县| 珠海市| 奉化市| 灌阳县| 阿拉善右旗| 任丘市| 乌恰县| 浦江县| 定州市| 陆河县| 江孜县| 北安市| 浦县| 泸西县| 佛学| 龙海市| 庐江县| 平和县| 进贤县| 汤阴县| 北票市| 吉林省|