- shell 的 PID:『 echo $$ 』
- 指令回傳值:『 echo $? 』
- 連續指令的種類:『 ; 』、『 && 』、『 || 』
- shell 的 PID:『 echo $$ 』
- 指令回傳值:『 echo $? 』
- 連續指令的種類:『 ; 』、『 && 』、『 || 』
- 連續指令『 cmd1 』失敗的結果:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@rhel7 ~]# echo $$ | |
6601 | |
[root@rhel7 ~]# ps aux |grep 6601 | |
root 6601 0.0 0.4 115484 2124 pts/0 Ss 13:03 0:00 -bash | |
root 7450 0.0 0.1 112640 980 pts/0 S+ 13:32 0:00 grep --color=auto 6601 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@rhel7 ~]# true | |
[root@rhel7 ~]# echo $? | |
0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@rhel7 ~]# false | |
[root@rhel7 ~]# echo $? | |
1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@rhel7 ~]# id || pwd | |
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@rhel7 ~]# id && pwd | |
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 | |
/root |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@rhel7 ~]# id ; pwd | |
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 | |
/root |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@rhel7 ~]# false || echo "Oops, fail" | |
Oops, fail | |
[root@rhel7 ~]# true || echo "Will not be printed" | |
[root@rhel7 ~]# true && echo "Things went well" | |
Things went well | |
[root@rhel7 ~]# false ; echo "This will always run" | |
This will always run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@rhel7 ~]# foo || id | |
-bash: foo: command not found | |
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 | |
[root@rhel7 ~]# foo && id | |
-bash: foo: command not found | |
[root@rhel7 ~]# foo ; id | |
-bash: foo: command not found | |
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 |