What platform independent way to find directory of shell executable in shell script?

前端 未结 2 1887
我寻月下人不归
我寻月下人不归 2021-01-19 03:03

According to POSIX:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html

there are some cases where it not obvious. For example:



        
2条回答
  •  不知归路
    2021-01-19 03:10

    I believe you can get it using readlink:

    scriptPath=$(readlink -f -- "$0")
    scriptDirectory=${scriptPath%/*}
    

提交回复
热议问题