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] Shell quoting mystery

[ILUG] Shell quoting mystery

Brian Foster blf at utvinternet.ie
Sat May 24 14:45:14 IST 2008


  | Date: Sat, 24 May 2008 13:42:27 +0200
  | From: Andrew <glug at lunch.za.net>
  |[ ... ]
  | If you want to set up the command in variables beforehand,
  | you could do it like this:
  |   FINDRX_C[0]="-name"
  |   FINDRX_C[1]="core.*"
  |   FINDRX_C[2]="-o"
  |   FINDRX_C[3]="-name"
  |   FINDRX_C[4]="core"
  | # then you see your required result with:
  |   find "${FINDRX_C[@]}"
  | which with set -x says:
  | + find -name 'core.*' -o -name core

 yes, this is another way of specifying array element
 values.  I almost never use it.  surprisingly often,
 the short simple and obvious (but ‘bash’-specific):

      FINDRX_C=( -name core.\* -o -name core )
      find "${FINDRX_C[@]}"

 and variants suffices.

  | At this point, you would be justified in thinking there's a better way.

 why?  a list of strings — which in ‘bash’ is called
 an array — is precisely what is needed.  that is,
 after all, precisely what command arguments are.
 this probably _is_ the best way, albeit you can write
 it in ways which obfuscate the trivialness of it all.

cheers!
	-blf-
-- 
“How many surrealists does it take to    |  Brian Foster
 change a lightbulb?  Three.  One calms  |  somewhere in south of France
 the warthog, and two fill the bathtub   |     Stop E$$o (ExxonMobil)!
 with brightly-coloured machine tools.”  |       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