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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章