Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Escaping spaces in arguments to shell script



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





BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org