Wednesday July 21, 2004
Korn shell arrays
Korn shell supports arrays. You can have about 4000 elements in a korn shell array, and the performance is not great, but they're quite handy for walking through sets of variables (like paths).
The syntax is:
set -A <array> [values...]This will set the array named to the values passed, clearing the variable before setting. This is fine, but what if we're simply appending to an array? Lots of folks want to do that. In this case what you use is:
set +A <array> [values...]All very fine and well, but how do we reference the values in the array? You use the variable[<index>] syntax.
array[<index>]=<value>What about getting all the values from the array? simply use either @ or * as the index.
Then there's dereferencing it. Dereferencing the entry involves using ${array[index]}, otherwise the $ would evaluate up to the left bracket, and not evaluate the content of the array, such is the grammar of ksh.
Putting this all together into something useful (like a gcc wrapper for gcc specific options)
set -A arguments -- "$@"
typeset -i index=0
while [[ -n ${arguments[$index]} ]]; do
case ${arguments[$index]} in
-W|-Wall)
arguments[$index]=-v;;
-Werror)
arguments[$index]=-errwarn=%all;;
-O?)
arguments[$index]=-xO${arguments[$index]##-O};;
esac
index=$((index + 1))
done
cc -xCC "${arguments[@]}"
July 21, 2004 03:00 PM IST
Permalink
Liveupgrade - the script
I use the Script to upgrade my machine whenever a new build comes out of Solaris. It allows me to not have to remember to issue the necessary upgrade commands.
It illustrates the use of the live upgrade cli commands to automate the upgrading of a machine into a pre-configured alternate boot environment.
July 21, 2004 02:04 PM IST
Permalink