evaluating ${10} and above in sh/ksh

Robert Hartman hartman at ide.com
Tue Aug 14 02:35:32 AEST 1990


In article <514 at risky.Convergent.COM> chrisb at risky.Convergent.COM (Chris Bertin) writes:
>There doesn't seem to be a way, in sh or ksh, to evaluate $10 and higher.
>$10 and higher are evaluated as ${1}0, ${1}1, etc...
>		     instead of ${10}, ${11}, etc...
>I have tried many different ways and they all fail. Do you know one
>that will work?
>

This is what the shift builtin is for:

# sort out arguments
while [ $# -gt 0 ] ; do
    case $1 in
        -a)  a=true  ;;
        -b)  b=true  ;;
 	-*)  "echo illegal option" ;;
	*)   "$files $i"   ;;
    esac
    shift
done

This will process through all of your arguments and build a list of filenames.
It doesn't work if options can have arguments of their own.  For cases like
this, I use getopts to parse out the command line.  There's a good example in
the getopts man page.

-r



More information about the Comp.unix.wizards mailing list