The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Switch + stirng DNAx86 Shell Programming and Scripting 5 01-09-2008 10:10 AM
switch login sharif UNIX for Advanced & Expert Users 1 12-12-2007 04:03 AM
Switch abey High Level Programming 12 06-27-2006 07:11 PM
switch from csh to ksh veeracer Shell Programming and Scripting 8 11-05-2004 02:13 PM
switch from csh to ksh veeracer UNIX for Dummies Questions & Answers 1 11-03-2004 06:28 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-30-2001
neer45 neer45 is offline
Registered User
  
 

Join Date: Nov 2001
Location: san jose,ca
Posts: 6
Angry can you switch

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
  #2 (permalink)  
Old 12-01-2001
rwb1959's Avatar
rwb1959 rwb1959 is offline
Registered User
  
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
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.
  #3 (permalink)  
Old 12-03-2001
neer45 neer45 is offline
Registered User
  
 

Join Date: Nov 2001
Location: san jose,ca
Posts: 6
Question csh switch

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
  #4 (permalink)  
Old 12-05-2001
rwb1959's Avatar
rwb1959 rwb1959 is offline
Registered User
  
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:39 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0