LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] Passing arguments containing spaces

[ILUG] Passing arguments containing spaces

Brian Foster blf at blf.utvinternet.ie
Fri Dec 30 18:04:23 GMT 2005


  | Date: Fri, 30 Dec 2005 14:39:25 +0000
  | From: Liam O'Hagan <liam at liamohagan.com>
  | 
  |[ ... ] if I do this :
  | command=3D"mp3info -a \"Louis Armstrong\" -l \"The Essential Louis\" -t \
  |   \"Basin Street Blues\" \"Basin Street Blues.mp3\""
  | 
  | Then issue :
  | $command
  | 
  | [ it obviously won't work ].

 as others have pointed out, for what yer doing,
 you should consider rewriting it as command='...'
 (mostly for clarity) and then, in any case, use eval.

 the problem here is since eval effectively re-parses
 its arguments, if you have a shell metacharacter such
 as $ or ? or * or ` or so on as part of the value of
 $command, you may run into additional problems.

 there is _another_ way of doing essentially what
 yer doing that does not have that glitch:

    declare -a command=( mp3info -a "Louis Armstrong" ... )
    "${command[@]}"

 i.e., use an array.  no need for strange quoting,
 no need for an eval, and no problems with embedded
 $, ?, *, and so on.  the above syntax is, AFAIK,
 GNU bash(1)-only, albeit there is an equivalent
 in the Korn shell (ksh(1)).
 ( for various other Bourne-ish shells without
  arrays, there is a kludge or two which is
  equivalent to the above. )

cheers!
	-blf-
-- 
Experienced (20+ yrs) kernel/software Eng: | Brian Foster   Montpellier,
 • Unix, embedded, &tc;  • Linux;  • doc;  | blf at utvinternet.ie   FRANCE
 • IDL, automated testing, process, &tc.   |  Stop E$$o (ExxonMobile)!
Résumé (CV) http://www.blf.utvinternet.ie  |     http://www.stopesso.com



More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell