How to detect the current directory in which I run my shell script?

后端 未结 4 523
后悔当初
后悔当初 2021-02-07 03:40

How may I detect the name of the directory (or better yet the entire path) in which my shell script is run?

4条回答
  •  清歌不尽
    2021-02-07 04:35

    This, I believe, is the most portable way:

    dir=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
    

提交回复
热议问题