Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Case statement not working as expected

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-26-2013
Michael Stora Michael Stora is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 22 June 2015, 3:25 PM EDT
Posts: 183
Thanks: 56
Thanked 15 Times in 13 Posts
Case statement not working as expected


Code:
            case "$freq" in
            [2,2.5,3.15,4,5,6.3]" Hz")          low=250; high=550;;
            "8 Hz")                             low=250; high=1000;;
            [10,12.5,16,20,25,31.5,40,50]" Hz") low=400; high=1000;;
            "63 Hz")                            low=550; high=1000;;
            [80,100,125,160,200,250]" Hz")      low=400; high=550;;
            *)                                  low=error; high=error;;
            esac

The strings containing decimal places like "6.3 Hz" are not being found in the case statement. I have tried putting "6.3" or '6.3' around the individual entries.

Can someone explain what is going on here?

Mike
Sponsored Links
    #2  
Old Unix and Linux 03-26-2013
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 31 August 2016, 5:33 PM EDT
Location: Amsterdam
Posts: 10,988
Thanks: 427
Thanked 3,037 Times in 2,699 Posts
The syntax is not correct ( [..] denote a single character that can be any of the characters specified inside them). Try:

Code:
  case ${freq% Hz} in
    2|2.5|3.15|4|5|6.3)  ...


Last edited by Scrutinizer; 03-26-2013 at 03:56 PM..
The Following User Says Thank You to Scrutinizer For This Useful Post:
Michael Stora (03-26-2013)
Sponsored Links
    #3  
Old Unix and Linux 03-26-2013
Michael Stora Michael Stora is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 22 June 2015, 3:25 PM EDT
Posts: 183
Thanks: 56
Thanked 15 Times in 13 Posts
Will do, thanks.

Mike

edit: works fine

Last edited by Michael Stora; 03-26-2013 at 04:35 PM..
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
If statement with [[ ]] and regex not working as expected Michael Stora Shell Programming and Scripting 5 03-20-2013 12:48 PM
echo is not working as expected afahmed Shell Programming and Scripting 7 11-21-2011 10:17 AM
Why this is not working in expected way? meharo Shell Programming and Scripting 4 12-07-2009 08:47 AM
ls not working as expected within ksh GNMIKE Shell Programming and Scripting 10 07-07-2005 07:53 AM
which not working as expected osee Shell Programming and Scripting 2 09-07-2004 11:37 AM



All times are GMT -4. The time now is 09:51 PM.