Case Instruction


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Case Instruction
# 1  
Old 10-31-2007
Case Instruction

Hi,
this is my script to make a choice between 4 :

clear
echo " choose a profile and enter a number"
echo
echo " 1- oraSTT "
echo
echo " 2- appSTT "
echo
echo " 3- oraPDD "
echo
echo " 4- appPDD "
read Keypress
case "$Keypress" in
[1] )
echo "oraSTT"
PATH=/Data/oracle/d03/STTdb/9.2.0/bin:$PATH
export PATH
. /Data/oracle/d03/STTdb/9.2.0/STT_os03erd.env
;;
[2] ) echo "appSTT";;
[3] ) echo "oraPDD";;
[4] ) echo "appPDD";;


After choosing first one (1) only
echo "oraSTT"
is executed. The others :


PATH=/Data/oracle/d03/STTdb/9.2.0/bin:$PATH
export PATH
. /Data/oracle/d03/STTdb/9.2.0/STT_os03erd.env
;;


are not. What is wrong in my script ?
Many thanks.
# 2  
Old 10-31-2007
if you're scripting in ksh, look into 'select' in 'man ksh'
# 3  
Old 11-01-2007
Thank you , do you mean that we can not use "case" ?
Here is a part of man ksh :
case word in [ [(] pattern [| pattern] ... ) list ;; ] ... esac
The case statement attempts to match word against the specified patterns; the list associated with the first successfully matched pattern is executed. Pat-
terns used in case statements are the same as those used for file name patterns except that the restrictions regarding . and / are dropped. Note that any
unquoted space before and after a pattern is stripped; any space with a pattern must be quoted. Both the word and the patterns are subject to parameter,
command, and arithmetic substitution as well as tilde substitution. For historical reasons, open and close braces may be used instead of in and esac (e.g.,
case $foo { *) echo bar; }). The exit status of a case statement is that of the executed list; if no list is executed, the exit status is zero.

select name [ in word ... term ] do list done
where term is either a newline or a ;. The select statement provides an automatic method of presenting the user with a menu and selecting from it. An enu-
merated list of the specified words is printed on standard error, followed by a prompt (PS3, normally â#? â). A number corresponding to one of the enumer-
ated words is then read from standard input, name is set to the selected word (or is unset if the selection is not valid), REPLY is set to what was read
(leading/trailing space is stripped), and list is executed. If a blank line (i.e., zero or more IFS characters) is entered, the menu is re-printed without
executing list. When list completes, the enumerated list is printed if REPLY is null, the prompt is printed and so on. This process is continues until an
end-of-file is read, an interrupt is received or a break statement is executed inside the loop. If in word ... is omitted, the positional parameters are
used (i.e., "$1", "$2", etc.). For historical reasons, open and close braces may be used instead of do and done (e.g., select i; { echo $i; }). The exit
status of a select statement is zero if a break statement is used to exit the loop, non-zero otherwise.


As you can see in both it is possible to have a list of instructions.
Regards.
# 4  
Old 11-02-2007
Error That may be a typing error


Have you tried putting ';' (semicolon) after your statement
echo "oraSTT"

I guess, you would need 1 semicolon after each statement except the last one.
See if this works:

Quote:
echo "oraSTT";
PATH=/Data/oracle/d03/STTdb/9.2.0/bin:$PATH;
export PATH;
. /Data/oracle/d03/STTdb/9.2.0/STT_os03erd.env
;;
Note there are 2 semicolons after your last statement
. /Data/oracle/d03/STTdb/9.2.0/STT_os03erd.env


Last edited by bright_future; 11-02-2007 at 04:11 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Illegal Instruction error

I keep getting a Illegal instruction error when running my MCP file below is the dump error message followed by truss log, dose anyone have any ideas? /opt/builds/bin/core: ELF 32-bit MSB core file SPARC Version 1, from 'mcp' *** Select Close or Exit from the window menu to close this window... (12 Replies)
Discussion started by: Wpgn
12 Replies

2. Shell Programming and Scripting

Cp –r instruction

Pleas I want answer to this question? Pleas help me A system administrator suspects that there is an attack on his machine; he needs to make a backup of the files to check when they have been modified. For this purpose he uses the "cp -r" instruction to copy the root directory. What is the... (1 Reply)
Discussion started by: tamer11007
1 Replies

3. Shell Programming and Scripting

Open_ssh installation instruction ?

Hi , Currently the machine (solaris 10 ) is running with Sun_ssh. I would like to move to Open_ssh. I went through google. Each link shows different directions/ways to install openssh. I am not sure which one to follow . Installing OpenSSH Packages - SPARC and Intel x86/Solaris 9 and... (1 Reply)
Discussion started by: frintocf
1 Replies

4. Solaris

Openssh installation instruction ?

Hi , Currently the machine is running with Sun_ssh. I would like to move to Open_ssh. I went through google. Each link shows different directions/ways to install openssh. I am not sure which one to proceed with . Installing OpenSSH Packages - SPARC and Intel x86/Solaris 9 and 10 ... (0 Replies)
Discussion started by: frintocf
0 Replies

5. Shell Programming and Scripting

How verify that the last instruction was success ?

Hi gusys. I am developing a script that mount a filesystem ; I would like verify that this instruction has finished OK !!! I am tryin to use $? ; but I have doubt How use the if instruction with the $? variable : mount machine:/dir /dir if then action 1 else ... (2 Replies)
Discussion started by: aggadtech08
2 Replies

6. Shell Programming and Scripting

Script needed to select and delete lower case and mixed case records

HELLO ALL, URGENTLY NEEDED A SCRIPT TO SELECT AND DELETE LOWER AND MIXED CASE RECORDS FROM A COLUMN IN A TABLE. FOR EXAMPLE : Table name is EMPLOYEE and the column name is CITY and the CITY column records will be: Newyork washington ... (1 Reply)
Discussion started by: abhilash mn
1 Replies

7. Solaris

what is that 1 in the instruction!~ (please help fast)

Hi all, make_lofs /.cdrom/<something>/<something> 1 what does this instruction mean? Note:both the "something" are obviously different . I would like to know what that 1 means, the rest of the instruction is clear!! Thanks (6 Replies)
Discussion started by: wrapster
6 Replies

8. Shell Programming and Scripting

Illegal instruction(coredump)

Hi I am trying to execute a simple grep command looking for records in a filename that start with 01 (grep ^01 filename) and am getting the error Illegal instruction(coredump). Has anyone any idea why this happens? Is it due to the file being corrupted? Thanks (1 Reply)
Discussion started by: colinmas
1 Replies

9. UNIX for Dummies Questions & Answers

2489 Illegal instruction

Hello I am trying to execute a back up from one queue manager from one script saveqmgr.sh but I am getting 2489 Illegal instruction on line 16 $ sh +x ./saveqmgr.sh S1SEAGULL QueueManager=S1SEAGULL Retention= S1SEAGULL.MQS.14Jan2005 not found ./saveqmgr.sh: 2836 Illegal... (1 Reply)
Discussion started by: ana
1 Replies

10. UNIX for Dummies Questions & Answers

lower case to upper case string conversion in shell script

How can convert a Lower case variable value to an upper case in the kron shell script. (3 Replies)
Discussion started by: dchalavadi
3 Replies
Login or Register to Ask a Question