hi,
i am try to run following script in c-shell, using switch command.
#!/bin/csh
choice=0
while [ $choice -ne 9 ]
do
echo "system monitor"
echo "
1) system paging
2) system file inf.
3) system disk inf.
9) exit
"
echo "select an option: \c"
read choice
case $choice in
1) sar -p;;
2) sar -u;;
3) diskusage -p;;
9) ;;
*) echo 'Invalid choice'
sleep 1;;
esac
done
Personally, I would stay away from csh but...
In csh, the "switch" is used...
switch (string)
case str1:
...
breaksw
...
default:
...
breaksw
endsw
In your script:
...
read choice
switch ($choice)
case 1:
sar -p
breaksw
case 2:
sar -u
breaksw
case 3:
diskusage -p
breaksw
case 9:
breaksw
default:
echo 'Invalid choice'
breaksw
endsw
...
The numbers in the case lines may have to be
strings like: case "1":
Since I haven't use csh in many years, I don't
recall exactly.
hi ,
this is neer45. I try to run csh switch script. but i get syntex error :-
sunserver% sh monitor
system monitor
1) system paging
2) system file inf.
3) system disk inf.
4) current operating system.
5) print report
select an option
5
monitor: syntax error at line 12: `switch' unexpected
---------------------------
thank you for your help
First make the script executable...
chmod 755 monitor
...then change the line...
read choice
...to...
set choice = $<
...sorry I did not pick this up before.
It has been many years since I've used csh.
Do NOT use "sh monitor" to execute. Just
type the script's name.