Escaping spaces in arguments to shell script
Steven Erat
stevenerat at yahoo.com
Wed Apr 26 12:56:23 EDT 2006
Would someone kindly suggest the solution to passing input parameters to a
shell script where the arguments may contain spaces?
Please refer to the example below.
Thank you,
Steven Erat
[auser at localhost ~]$ ls
makeLink.sh
[auser at localhost ~]$ cat makeLink.sh
#!/bin/sh
echo First arg is: $1, Second arg is $2
/bin/ln -s $1 $2
[auser at localhost ~]$ mkdir foo
[auser at localhost ~]$ ./makeLink.sh foo foo\ bar
First arg is: foo, Second arg is foo bar
/bin/ln: when making multiple links, last argument must be a directory
[auser at localhost ~]$ ln -s foo boo\ hoo
[auser at localhost ~]$ ls -l
total 20
lrwxrwxrwx 1 auser auser 3 Apr 26 11:50 boo hoo -> foo
drwxrwxr-x 2 auser auser 4096 Apr 26 11:49 foo
-rwxr-xr-x 1 auser auser 68 Apr 26 11:44 makeLink.sh
[auser at localhost ~]$ ./makeLink.sh foo 'some\ thing'
First arg is: foo, Second arg is some\ thing
/bin/ln: when making multiple links, last argument must be a directory
More information about the Discuss
mailing list