OSX How do I install the script shell change directory in the folder where the script is located?

I use an Apple machine to create a Script wrapper. I can make it run if I hide the directory specifically where the jar file is located. But what if I want to change the directory to where the Shell script works?

Now I have the following:

cd desktop/CommonDenom/
java -XstartOnFirstThread -jar CommonDenom.jar

I know that there is a way to target any directory from which the shell script is launched, but I cannot get anything to work. Please be specific with the instructions, as I have not used Automator for a very long time. If someone cannot specify how ot to write ethe script without Automator. Thanks in advance.

+4
source share
3 answers

The standard idiom for this in shell scripts is dirname $0. A variable $0is the path to the script that was executed, and the command dirnametakes the path and removes the last component to leave the path to the containing directory

cd "`dirname $0`"
+3
source

Just wanted to weigh it here. I have seen some people with this problem. If you are just on OSX and create your own scripts. This will do the trick :) like hacking, but it works like a charm.

#! /bin/bash 

sudo /Applications/XAMPP/xamppfiles/xampp startapache

open /Applications/XAMPP/htdocs
+1
source

, " , script", , script , . , , , script , , jar.

, , :

java -XstartOnFirstThread -jar ~/Desktop/CommonDemon/CommonDemon.jar
0
source

Source: https://habr.com/ru/post/1530852/


All Articles