dealing with lots of arguments in bash
#!/bin/sh #DTPD# echo first argument is '"'${1}'"' for argc in `seq 2 $#`; do eval arg=\${$argc} echo ${argc}th arg is $arg done
For example:
#!/bin/sh # prepend-something.sh #DTPD# if [ "$#" -lt 2 ] ; then echo "useage: $0 PREFEX FILE[S]" exit 1 fi PREFEX=${1} for argc in `seq 2 $#`; do eval arg=\${$argc} mv -v "${arg}" "${PREFEX}${arg}" done
Update 2009-12-05: Another way to do it would be to use the shift command.
#!/bin/sh # prepend-something.sh #DTPD# if [ "$#" -lt 2 ] ; then echo "useage: $0 PREFEX FILE[S]" exit 1 fi prefix=${1} shift for arg in "$@"; do mv -v "$arg" "${prefix}${arg}" done