Reputation: 1774
I created a bash script called test.sh
that accepts one command line argument:-
$ cat test.sh
#!/bin/bash
open -a Terminal $1
When i execute this script in the following way:-
$ ./test.sh /Users/myusername/Desktop/folderwithoutspaces/
it executes perfectly and launches a new Terminal window in the given folder.
But when i execute this script in the following way:-
$ ./test.sh /Users/myusername/Desktop/folder\ withspaces/
it fails to open a new Terminal window and shows the following error message:-
The files /Users/myusername/Desktop/folder and /Users/myusername/Desktop/withspaces do not exist.
I tried all these possible ways but wasn't successful at any:-
$ ./test.sh "/Users/myusername/Desktop/folder\ withspaces/"
$ ./test.sh "/Users/myusername/Desktop/folder withspaces/"
$ ./test.sh '/Users/myusername/Desktop/folder\ withspaces/'
$ ./test.sh '/Users/myusername/Desktop/folder withspaces/'
$ ./test.sh /Users/myusername/Desktop/folder\ withspaces/
Upvotes: 2
Views: 5712
Reputation: 123458
When you use the variable with quoting, it gets split based on IFS
(which includes a whitespace by default). The solution is to quote the variable. Instead of saying:
open -a Terminal $1
say:
open -a Terminal "$1"
Upvotes: 5