I feel stupid -- determine the full path to a file
Andy Bradford
amb-plug at bradfords.org
Tue Dec 11 21:39:58 MST 2007
Thus said Andrew McNabb on Thu, 06 Dec 2007 15:57:03 CST:
> argument_list="arg1 arg2 arg3"
> some_program $argument_list
>
> Unfortunately, I could find no way to execute a program with a
> variable length list of arguments. The following works, but requires a
> fixed number of arguments:
How about something like:
set "arg1" "arg2" "arg3"
some_program "$@"
Here's a fun little script that demonstrates this by dynamically
altering the arguments (decreasing them as it goes):
------------------------------------------------------------------------
#!/bin/sh
if [ "$#" -gt 0 ]
then
echo "$# args are: $@"
shift
if [ "$#" -ne 0 ]
then
set "$@"
fi
"$0" "$@"
fi
------------------------------------------------------------------------
Call it as:
./shellscript "arg 1" "arg 2" "arg 3" "arg 4" "arg 5"
This will run 5 times (only 5 arguments) and output five lines.
Of course if your original script uses the positional parameters you
will want to save them off first.
Cheers,
Andy
--
[-----------[system uptime]--------------------------------------------]
9:38pm up 1:11, 1 user, load average: 1.00, 1.00, 1.00
More information about the PLUG
mailing list