Returning value from called function in a shell script

后端 未结 5 528
自闭症患者
自闭症患者 2020-11-27 08:55

I want to return the value from a function called in a shell script. Perhaps I am missing the syntax. I tried using the global variables. But that is also not working. The c

5条回答
  •  旧时难觅i
    2020-11-27 09:50

    You are working way too hard. Your entire script should be:

    if mkdir "$lockdir" 2> /dev/null; then 
      echo lock acquired
    else
      echo could not acquire lock >&2
    fi
    

    but even that is probably too verbose. I would code it:

    mkdir "$lockdir" || exit 1
    

    but the resulting error message is a bit obscure.

提交回复
热议问题