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

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

主站蜘蛛池模板: 奎屯市| 新兴县| 邵东县| 望谟县| 抚顺县| 新乐市| 宁德市| 石河子市| 方城县| 宜宾市| 宜都市| 镇宁| 惠安县| 金秀| 灵宝市| 万盛区| 濮阳县| 牟定县| 宿迁市| 江口县| 于田县| 台中市| 永新县| 宁安市| 怀宁县| 淳安县| 石家庄市| 靖江市| 乐至县| 崇左市| 烟台市| 河北省| 资源县| 平湖市| 洛隆县| 胶南市| 吉林省| 长治市| 宜宾市| 延寿县| 墨竹工卡县|