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

  • 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.

主站蜘蛛池模板: 广河县| 顺义区| 米脂县| 稷山县| 甘德县| 轮台县| 金川县| 平果县| 清水河县| 思南县| 响水县| 泾川县| 平潭县| 六盘水市| 龙江县| 曲麻莱县| 二手房| 浦江县| 都江堰市| 维西| 凤台县| 姜堰市| 当涂县| 石狮市| 苏尼特左旗| 吉木萨尔县| 梁山县| 张家界市| 安宁市| 浏阳市| 宁乡县| 兰州市| 仁寿县| 柞水县| 新乡县| 长泰县| 宕昌县| 成都市| 攀枝花市| 岱山县| 石嘴山市|