Problem w. case structure


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Problem w. case structure
# 1  
Old 07-19-2003
Problem w. case structure

Hello,

I am having a problem setting a range of numbers for the "case" structure.

I can use [a-z] with no problems, but
when I use [0-60] it doesn't work???

Does the case struture allow numeric ranges?

eg:

echo -e "enter number between 0 and 60: \c"
read $answer

case $answer in
[0-60] ) echo "number between 0 and 60" ;;
esac

Thanks,

Joe
# 2  
Old 07-19-2003
No, that doesn't work. The 0-6 represents, well, 0 through 6. And then the final 0 represents just zero again. You will need to use an "if" statement of some kind. In ksh, I would do:

if ((answer >= 0 && answer <=60)) ; then

You have something else that doesn't work. You can't (generally) do:
read $answer
it should be
read answer
# 3  
Old 07-19-2003
Hi Perderabo,

Thanks for the help, greatly appreciated!

After reading your answer that [0-60] would be read [0-6] I wondered if you could specify a range for the first entry and another range for the second entry... apparenty you can... this seems to work...

echo -e "Enter a numeric value (0-100): \c"
read answer

case $answer in
[0-9] ) echo "number between 0-59" ;;
[1-5][0-9] ) echo "number between 0-59" ;;
esac

I also did it with an "If" structure and it's easilly done.

Thanks for picking out the $answer error too...

Thanks again Perderabo,

Joe
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Malloc problem with fread() to read file to structure in C

Hello, I am trying to read a text file into linked list, but always got the first and last records wrong. 1) The problem looks related to the initialization of the node temp with malloc(), but could not figure it out. No error/warning at compiling, though. 2) The output file is empty,... (10 Replies)
Discussion started by: yifangt
10 Replies

2. UNIX for Dummies Questions & Answers

Problem with structure of authlog in regard to an external log Auditing system.

Hello everyone, I hope I'm posting my question in the right section as it is not too easy to find the ideal spot for this one, especially for a brandspankingnew user of this forum. As this might be something simple I chose the Dummy section. By all means, feel free to move the post if not at... (4 Replies)
Discussion started by: Sjleegketting
4 Replies

3. Shell Programming and Scripting

Case structure combined with standard input

Hi folks, I am new to bash scripting so please excuse my question. Is there any chance to combine a case structure with the read command? Like case (read -p "" variable) in x) Thx! (7 Replies)
Discussion started by: haukee
7 Replies

4. Shell Programming and Scripting

case structure in .sh file

Hi, while true do printf "$FBOLD\nPlease enter the minutes (0-59): $FREG" read MIN case "$MIN" in ||s) break 2;; *) echo "" echo "Invalid minutes, please try again.";; esac done In the above... (4 Replies)
Discussion started by: milink
4 Replies

5. UNIX for Dummies Questions & Answers

Fall through case structure

Hello Experts, I was wondering how can we get a fall trough case structure. Eg: If we have two cases A and B and a default; if I do not break after A, it should execute all the statements of A as well as B if I break after B else fall through even lower. I tried this: #!/bin/sh v1=1... (6 Replies)
Discussion started by: hkansal
6 Replies

6. UNIX for Dummies Questions & Answers

ksh case structure

Hello Experts, I ve been trying to build another shell where I am using the following code. transact="tv5cpc1" case "$transact" in "...cp..") xActType="" ;; "...de..") xActType="sp_dep" ;; "...ep..") xActType="sp_epa" ;; "....v.") ... (4 Replies)
Discussion started by: hkansal
4 Replies

7. Programming

Problem in static structure array in C

Hi, I have a following problem in C. I have a function A in which I used to call another function (function B) and pass an array of values through array variable by using below:- foo=functionB(array); In functionB, i used to just return some "values" (e.g return num;) in order to pass... (1 Reply)
Discussion started by: ahjiefreak
1 Replies

8. Shell Programming and Scripting

problem with listing of directory structure

Hi When im listing (ls -al ) its listing directories without / at the end of directories dir1 dir2 dir3 and i need to list directories with dir1/ dir2/ dir3/ and this should not be made by command ls -F / should be embedded at the last since one of the scripts reads directories... (1 Reply)
Discussion started by: vasanthan
1 Replies

9. Programming

Search attributes in one structure using the values from another structure

Hello Groups I am trying to find out ways of comparing a value from a 'c' structure to a value in another 'C' structure. the 'C' structure can be a List or liked list as it contains lot many records. if we loop it in both the structures it is going to consume time. I am looking for a simple... (3 Replies)
Discussion started by: dhanamurthy
3 Replies

10. Shell Programming and Scripting

Case structure

Hi, Can anyone help me with the following case structure? echo "Please enter the date for which you want the Report:\c" read dat d1=`echo $dat|cut -c7-8` m1=`echo $dat|cut -c5-6` y1=`echo $dat|cut -c1-4` yr=`expr "$d1" - 1` case "$yr" in 0) MONTH=`expr "$m1" - 1`... (4 Replies)
Discussion started by: kamitsin
4 Replies
Login or Register to Ask a Question