Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions 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: 2 December 2016, 2:51 AM EST
Location: Amsterdam
Posts: 11,096
Thanks: 440
Thanked 3,105 Times in 2,747 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 04: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 05: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 01:48 PM
echo is not working as expected afahmed Shell Programming and Scripting 7 11-21-2011 11:17 AM
Why this is not working in expected way? meharo Shell Programming and Scripting 4 12-07-2009 09:47 AM
ls not working as expected within ksh GNMIKE Shell Programming and Scripting 10 07-07-2005 08:53 AM
which not working as expected osee Shell Programming and Scripting 2 09-07-2004 12:37 PM



All times are GMT -4. The time now is 06:14 PM.