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