0

I created a .command file that runs a certain command java -jar myApp.jar in the Terminal, however it doesn't work because it first needs to cd into a certain directory.

Is there a way to make the .command file automatically go to the address where the .command file currently is, and execute the command from there?

I can't just add the cd line into the script because I need to distribute this and it needs to work no matter where on the computer it is.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Akiak
  • 13
  • 3

1 Answers1

0

In a bash script:

cd "$(dirname "$0")"

will cd into the directory containing the script.

glenn jackman
  • 238,783
  • 38
  • 220
  • 352