Case statement not working as expected | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Case statement not working as expected

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-26-2013
Michael Stora Michael Stora is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 18 September 2014, 4:02 PM EDT
Posts: 148
Thanks: 44
Thanked 14 Times in 12 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 03-26-2013
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 23 November 2014, 11:57 PM EST
Location: Amsterdam
Posts: 9,611
Thanks: 293
Thanked 2,448 Times in 2,196 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 03-26-2013
Michael Stora Michael Stora is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 18 September 2014, 4:02 PM EDT
Posts: 148
Thanks: 44
Thanked 14 Times in 12 Posts
Will do, thanks.

Mike

edit: works fine

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 11:00 AM.