1

I've written a bash script found at directory:

/home/harmelodic/.Jetbrains/CLion.sh

that performs the following:

#!/bin/sh

./clion*/bin/clion.sh

This is to run the clion.sh script found at:

/home/matthew/.Jetbrains/clion-2016.2.3/bin/clion.sh

If I open a terminal in /home/harmelodic/.Jetbrains/ and perform:

$ ./CLion.sh

It successfully runs and opens the CLion IDE.

However, if I use a launcher from Application Finder to perform a Command to execute the script (as shown below), the CLion IDE fails to open.

enter image description here

I'm completely stumped. I thought the Command input would run the script fine but it doesn't.
I've ensured that the script is executable and that it runs via terminal but it refuses to run via the launcher found in Application Finder.

Why, and how do I fix this?

1 Answers1

1

Well, we had a PEBCAK error...

I mistakenly thought that if I ran the script, the script would automatically know where itself was and would use it's current location as a relative path.
This is not the case, it turns out. The script will treat whatever location the user is running the script from as the path to use when referring to relative paths.

Meaning that if I went to /home/harmelodic/ and ran:

$ ./.Jetbrains/CLion.sh

The script would fail as it would look for /clion*/bin/clion.sh in:

/home/harmelodic/

instead of

/home/harmelodic/.Jetbrains/

The solution was to get the current directory of the script and then perform the command using the current directory combined with the relative path to mimic a relative path whilst actually using absolute paths:

#!/bin/sh

CURRENT_DIR=`dirname $0`

$CURRENT_DIR/clion*/bin/clion.sh

This works from any directory, meaning that it works within a launcher from Application Finder.