Shell script current directory?

后端 未结 5 1741
一生所求
一生所求 2020-12-23 16:18

What is current directory of shell script? I this current directory from which I called it? Or this directory where script located?

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-23 16:38

    As already mentioned, the location will be where the script was called from. If you wish to have the script reference it's installed location, it's quite simple. Below is a snippet that will print the PWD and the installed directory:

        #!/bin/bash
        echo "Script executed from: ${PWD}"
    
        BASEDIR=$(dirname $0)
        echo "Script location: ${BASEDIR}"
    

提交回复
热议问题