evaluating ${10} and above in sh/ksh

Maarten Litmaath maart at cs.vu.nl
Tue Aug 14 06:00:46 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...

Alas...  POSIX fixes this though: ${10} will work.

)I have tried many different ways and they all fail. Do you know one
)that will work?

	set a b c d e f g h i j k l m

	argv()
	{
		shift $1 2> /dev/null
		echo "$1"
	}

	echo `argv 10 "$@"`
	echo `argv 11 "$@"`
	echo `argv 20 "$@"`

Beware of "$@": many shells will expand it to a single null string if
there are no positional parameters present at all!  A safe workaround
is:
	${1+"$@"}

Check it out in the manual!
--
   "UNIX was never designed to keep people from doing stupid things, because
    that policy would also keep them from doing clever things."  (Doug Gwyn)



More information about the Comp.unix.questions mailing list