How can I get the source directory of a Bash script from within the script itself?

问题:

How do I get the path of the directory in which a Bash script is located, inside that script?如何获取其中的目录路径的Bash脚本所在,该脚本里面

I want to use a Bash script as a launcher for another application.我想使用 Bash 脚本作为另一个应用程序的启动器。 I want to change the working directory to the one where the Bash script is located, so I can operate on the files in that directory, like so:我想将工作目录更改为 Bash 脚本所在的目录,以便我可以对该目录中的文件进行操作,如下所示:

$ ./application

解决方案:

参考一: https://en.stackoom.com/question/Fa3
参考二: https://stackoom.com/question/Fa3
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章