linux脚本一行写多个命令

There are 3 ways to run multiple shell commands in one line:

1) Use ;

No matter the first command cmd1 run successfully or not, always run the second command cmd2:

# cmd1; cmd2
$ cd myfolder; ls   # no matter cd to myfolder successfully, run ls

2) Use &&

Only when the first command cmd1 run successfully, run the second command cmd2:

# cmd1 && cmd2
$ cd myfolder && ls  # run ls only after cd to myfolder

3) Use ||

Only when the first command cmd1 failed to run, run the second command cmd2:

# cmd1 || cmd2
$ cd myfolder || ls  # if failed cd to myfolder, `ls` will run

发表评论

电子邮件地址不会被公开。 必填项已用*标注