csh - now how about pseudo-arrays?
Peter Klammer
pklammer at pikes.Colorado.EDU
Thu Mar 30 08:53:01 AEST 1989
OK, I'm learning, I'm getting better at this...
Yes, our .cshrc ended with 'cd', apparently to initiate the pretty
prompt via the cd alias. So if I change that to 'cd .' instead, we
get the pretty prompt without reverting to HOME in every subshell.
Now I would like to know if csh can be warped into array-like subscripting.
I am trying to write a table-driven menu in a csh script, so that I can
loop through cases instead of adding another explicit paragraph of case
code whenever we expand the menu. Here's the rough outline:
------------------------------------------------------------
#csh
# menu4
@ n = 0
@ n += 1; set entry$n = (EXIT EXIT)
@ n += 1; set entry$n = (ADDUSER ADD a new user account)
@ n += 1; set entry$n = (MODUSER MODIFY a user account)
@ n += 1; set entry$n = (DELUSER DELETE a user account)
@ n += 1; set entry$n = (SHOWUSER SHOW a user account)
@ n += 1; set entry$n = (ADDCLASS Add a new CLASS)
@ n += 1; set entry$n = (ADDGROUP Add a new GROUP)
@ n += 1; set entry$n = (DELGROUP CANCEL a group)
@ n += 1; set entry$n = (INSTRUCT INSTRUCTION)
#This, for specific case 3, works:
set command = $entry3[1]
set prompt = "${entry3[2-]}"
echo The command $command will $prompt
#This, for general case i, fails, with message 'Variable Syntax':
@ i = 1
while( $i <= $n )
set command = ${entry$i[1]}
set prompt = "${entry$i[2-]}"
echo The command $command will $prompt
@ i += 1
end
------------------------------------------
That's as close as I have been able to get in a couple days trying
without the Anderson book. I'd be happy to consider another approach,
but for some other reasons we're kinda bound to doing it in C-shell.
(I'd rather do it in awk, but our awk here can't import the arv command
line, so it's (snicker) awkward.)
More information about the Comp.unix.questions
mailing list