【Linux面試真題】- shell腳本中“$?”標記的?途是什么?
【Linux面試真題】- shell腳本中“$?”標記的?途是什么?
答:在寫?個shell腳本時,如果你想要檢查前?命令是否執(zhí)?成功,在if條件中使 ?“$?”可以來檢查前?命令的結束狀態(tài)。
簡單的例?如下: root@localhost:~# ls /usr/bin/ root@localhost:~# echo $? 0如果結束狀態(tài)是0,說明前?個命令執(zhí)?成功。 root@localhost:~# ls /usr/bin/share ls: cannot access /usr/bin/share: No such file or directory root@localhost:~# echo $? 2如果結束狀態(tài)不是0,說明命令執(zhí)?失敗。