tags:

views:

17

answers:

2

I have ./basscript parm1 parm2 parm3

I want to iterate through the parms starting from parm2 till parmN and append them to a variable.

How do I get ${COMPLETE}="parm1,parm2,parmN"?

A: 

Maybe something like this:

COMPLETE=""
shift
for a in "$@"
do
        if [ "$COMPLETE" == "" ]; then COMPLETE="$a"; else COMPLETE="$COMPLETE,$a" ; fi
done
echo $COMPLETE

This makes COMPLETE a comma-separated list of all the parameters, excluding the first.

unwind
If i put this in i get "[: 56: ==: unexpected operator "?
piet
shiftwhile test $# -gt 0doif [ "$MAIL_TO" == "" ]; then MAIL_TO="$1"; else MAIL_TO="$MAIL_TO,$1" ; fi shiftdoneecho "Will mail to ${MAIL_TO}"
piet
+2  A: 
IFS=","
echo  "${*:2}"
ghostdog74