& | If the execution result of the previous command in linux is correct, a $? Value = 0. So how can we determine whether to execute subsequent commands through this return value? This requires the help of & |! [Html] Example 1: Use ls to check whether the/tmp/abc directory exists. If yes, use touch to create/tmp/abc/hehe [root @ www ~]. # Ls/tmp/abc & touch/tmp/abc/hehe ls:/tmp/abc: No such file or directory # ls indicates that the directory cannot be found, however, the token does not have a touch history error, indicating that touch has not executed [root @ www ~]. # Mkdir/tmp/abc [root @ www ~] # Ls/tmp/abc & touch/tmp/abc/hehe [root @ www ~] # Ll/tmp/abc-rw-r -- 1 root 0 Feb 7 hehe saw it? If/tmp/abc does not exist, touch will not be executed. If/tmp/abc exists, touch will start to execute! [Html] Example 2: Test whether/tmp/abc exists. If not, create it. If not, [root @ www ~] # Rm-r/tmp/abc <= [root @ www ~] # Ls/tmp/abc | mkdir/tmp/abc ls:/tmp/abc: No such file or directory <= really does not exist! [Root @ www ~] # Ll/tmp/abc total 0 <== the result is displayed! Mkdir <span style = "font-size: 14px;"> </span> if I want to create a/tmp/abc/hehe file, but I don't know whether/tmp/abc exists. How should I do it? [html] Example 3: I don't know whether/tmp/abc exists, however, you need to create the/tmp/abc/hehe file [root @ www ~] # Ls/tmp/abc | mkdir/tmp/abc & touch/tmp/abc/hehe example three results are analyzed: (1) if/tmp/abc does not exist, return $? 0, then (2) Because | $? Therefore, mkdir/tmp/abc is started. Because mkdir/tmp/abc is successfully executed, $? is returned? = 0 (3) because & encounters $? If it is set to 0, touch (2) will be executed. If/tmp/abc exists, it will be returned. $? = 0, then (2) Because | 0 then $? Not executed. $? = 0 continue to pass back, so (3) as & encounters $? If it is set to 0,/tmp/abc/hehe is created! Finally,/tmp/abc/hehe is created.