Successfully launching a shell script from Finder when the path has a space in it

bashfinderterminal

Been trying to work this out this morning and beginning to wonder if this is even possible.

When launching a shell script through Finder, either by using the extension .command or opening .sh files in Terminal, the following command is executed:

Macbook-Pro:~ /Users/mulquin/Desktop/test/Path\ With\ Spaces/run.sh ; exit;
Could not open input file: /Users/mulquin/Desktop/test/Path

Trying it with quotes instead of escape characters yields the same result

Macbook-Pro:~ "/Users/mulquin/Desktop/test/Path With Spaces/run.sh" ; exit;
Could not open input file: /Users/mulquin/Desktop/test/Path

The users this is intended for are not tech savvy so asking them to open Terminal, browse to a directory and ./run.sh is unfortunately not an option.

I had a look at Platypus but the script location will be dynamic as the users will be running it from their desktops or other location they choose.

Has Apple really not noticed this issue or am I doing something wrong?

Best Answer

It turns out I was doing something wrong.

I erroneously believed the error message was caused by Mac OS X executing the script.

The reason this error was appearing was because inside my script I was executing something without escaping the space. Woopsie!