Khizar
Khizar

Reputation: 2308

Mac OS X: How to make the terminal open in the directory where the .command file is?

I am trying to make script files to push, pull etc my project from the bazaar server. In linux, i simply put the bzr commands in a .sh file , made it executable and it worked. But in Mac , when i put the bzr commands in a .command file, the terminal opened at my home folder and the commands were run there. which is obviously not what i intended. So what i found out was that to run in the folder i want, i first had to cd to this folder. Although this is working, but i want the scripts to be generic so that if i just copy it into a folder and it would run with the command prompt at that folder. Is there a better way to do this or would i have to keep changing the cd command in the scripts for all my projects??

Upvotes: 3

Views: 734

Answers (1)

Gordon Davisson
Gordon Davisson

Reputation: 125798

Start the scripts with cd "$(dirname "$0")"

Upvotes: 3

Related Questions