Linux命令執行順序— ||和&&和; command1 && command2: &&左邊的command1執行成功(返回0表示成功)后,&&右邊的command2才能被執行。 command1 || command2: 如果||左邊的command1執行失敗(返回1表示失敗),就執行&&右邊的command2。 command1;command2: 命令順序執行 //第一個命令執行不成功,第二個命令才執行 [tough@toughhou shell]cata||touchacat:a:Nosuchfileordirectory[tough@toughhoushell] ls a getpath.sh //第一個命令執行成功,第二個命令不執行 [tough@toughhou shell]cata||touchb[tough@toughhoushell] ls a getpath.sh //只有第一個命令(touch a)執行成功,才執行第二個命令(touch b) [tough@toughhou shell]touch a && touch b [tough@toughhou shell] ls a b getpath.sh //因為第一個命令執行不成功,所以第二個命令沒執行 [tough@toughhou shell]cat a1 && touch c cat: a1: No such file or directory [tough@toughhou shell] ls a b getpath.sh //命令順序執行 [tough@toughhou shell]$ pwd;more a;date /home/tough/shell 123 Sun Oct 13 10:24:55 CST 2013
剛才輸入命令 echo "This is file content, over!" > filename 竟然會出錯,提示:
bash: !": event not found
原來字符串中的!會被解析。如果不出錯的話呢,轉義!就可以了,如 \! ,
或者把雙引號改成單引號也行。