Run .command–file in the folder it's located?

I have a file called execute.command. When I execute it by opening it. It runs from my users folder. I would like it to run in the folder where it is located. is that possible?


You must change the script to change working directory to script-location directory:

#!/bin/bash
cd "$(dirname "$0")"

More answers here : Bash script: set current working directory to the directory of the script


I added cd dirname $0 to the top of the command line. This will cd you into the correct folder. Here are more details.

http://hints.macworld.com/article.php?story=20041217111834902

链接地址: http://www.djcxy.com/p/56786.html

上一篇: 简单的bash脚本挂在if语句中

下一篇: 在它所在的文件夹中运行.command文件?