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



Hi,

Quoting Steven Erat <stevenerat at yahoo.com>:

> Would someone kindly suggest the solution to passing input parameters to a
> shell script where the arguments may contain spaces?

Put quotes around it...

> [auser at localhost ~]$ cat makeLink.sh
> #!/bin/sh
> echo First arg is: $1, Second arg is $2
> /bin/ln -s $1 $2

Change this to:

  /bin/ln -s "$1" "$2"

Although that will probably have problems if you have embedded quotes
in your filenames.

-derek
-- 
       Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
       Member, MIT Student Information Processing Board  (SIPB)
       URL: http://web.mit.edu/warlord/    PP-ASEL-IA     N1NWH
       warlord at MIT.EDU                        PGP key available





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