The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 11-19-2007
cmcnorgan cmcnorgan is offline
Registered User
  
 

Join Date: Nov 2007
Location: London, Ontario, Canada
Posts: 2
Building command line parameters of arbitrary length

I couldn't find an existing thread that addressed this question, so hopefully this isn't redundant with anything previously posted. Here goes:

I am writing a C-Shell script that runs a program that takes an arbitrary number of parameters:

myprog -a file1 \
-b file2 \
-c file3 ... \
-n fileN \
-operation "a+b+c+...+n"


The files on which myprog operates are in subdirectories: 01/01.ext, 02/02.ext, ... etc.

Since the filenames happen to match the directory names, I would like to be able to pass the script an arbitrary number of directories (in practice, there will be fewer than 26, so there is no concern with running out of "-x" tags). The script would then construct the argument list for myprog so that
myscript.sh 01 02 03 ... 12
would expand into:
myprog -a 01/01.ext -b 02/02.ext ... -k 11/11.ext -l 12/12.ext \
-operation "a+b+c+...+k+l"


Is there a straightforward way to do this?