what does '$?' mean in a shell script?

前端 未结 6 1904
抹茶落季
抹茶落季 2021-02-02 00:31

I came across a shell script that contains a statement like,

if [ $val -eq $? ]

What does $? mean here?

6条回答
  •  孤街浪徒
    2021-02-02 00:58

    What does $? mean here?

    $? is the last result of an exit-status ... 0 is by default "successfull"

    bash# ls *.*
    bash# echo $? 
    bash# 0
    bash# ls /tmp/not/existing/
    bash# echo $?
    bash# 2
    

提交回复
热议问题