Unix shell script find out which directory the script file resides?

前端 未结 16 2167
我寻月下人不归
我寻月下人不归 2020-12-02 03:14

Basically I need to run the script with paths related to the shell script file location, how can I change the current directory to the same directory as where the script fil

16条回答
  •  失恋的感觉
    2020-12-02 04:00

    That should do the trick:

    echo `pwd`/`dirname $0`
    

    It might look ugly depending on how it was invoked and the cwd but should get you where you need to go (or you can tweak the string if you care how it looks).

提交回复
热议问题