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

后端 未结 4 522
后悔当初
后悔当初 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:22

    alternative method

    pid=$$
    path=$(ps -eo pid,args| awk -vp=$pid '$1~p{print $3}')
    case "$path" in
        ./* ) pwd;;
        * ) echo $path;;
    esac
    

提交回复
热议问题