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 | Blog | 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



Use quotes:  when invoke like
 ./makelink.sh foo "some thing"
$1 = "foo"
$2 = "some thing"

You're using a combination of quotes and escape ('\'), and therefore the escape
is being used literally.

Matt

Steven Erat wrote:
> 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
> 
> _______________________________________________
> Discuss mailing list
> Discuss at blu.org
> http://olduvai.blu.org/mailman/listinfo/discuss





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