Sponsored Content
Full Discussion: CASE statement
Top Forums UNIX for Dummies Questions & Answers CASE statement Post 302268334 by msb65 on Monday 15th of December 2008 12:02:03 PM
Old 12-15-2008
CASE statement

Hi,

I am writing a bash shell script. My script has a few user defined parameters. When the script runs the first thing it does is make sure that these parameters are valid. One of the parameters is called YEAR. A valid input for YEAR can be 1997-2000.

One way I have come up with to ensure that YEAR is valid is by using a case statement:

Code:
case $YEAR in 
    1997 | 1998 | 1999 | 2000 )
    echo  '- YEAR is valid'
    ;;
    *) 
    echo; echo; echo 'ERROR: YEAR is not valid (Must be 1997,1998,1999, or 2000)'
    exit 1
    ;;
esac

However, that is a simple case! In reality YEAR is valid for 1997-2008. Instead of listing each valid year in the case statement is there a way that I could just place all the valid years into an array and use that? ie:

Code:
YEAR_ARRAY=(1997 1998 1999 2000)

case $YEAR in 
    ${YEAR_ARRAY[@]} )
    echo  '- YEAR is valid'
    ;;
    *) 
    echo; echo; echo 'ERROR: YEAR is not valid (Must be 1997,1998,1999, or 2000)'
    exit 1
    ;;
esac

I have tried that and it doesn't work. Am I close? Is there a better way? Thanks a lot.

Mike
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

case statement

Hi all, is it possible to create a 'dynamic' case statement. ie select option in `ls` do case satement depending on results of the above `ls` done I hope I have explained this ok! Thanks Helen (1 Reply)
Discussion started by: Bab00shka
1 Replies

2. Shell Programming and Scripting

Case Statement

Can anyone please tell me why this wont work! Thanks so much! #!/bin/sh for file do case $file in *.*.*) echo Cannot have more than 1 dot exit ;; *'**'*) echo Cannot have more than 1 asterisk exit ;; *'*'*|?.) echo this is a target (19 Replies)
Discussion started by: Zeta_Acosta
19 Replies

3. Shell Programming and Scripting

case statement

hi all i'm writing a script and in it i need to prompt the user if the entered value is correct or not ,i wrote the following and its not working ,its executing the script even if i enter Y/N pls any help is appreciated echo "\nAre you sure you entered the right Destination Environment? y :... (5 Replies)
Discussion started by: bkan77
5 Replies

4. UNIX for Dummies Questions & Answers

If or Case Statement

I want to write a program with the following variables: a=7000 b=24000 c=613.8 The user can enter two words: Vivid or Blue for example. The challenge is that the user might not want to write the words the way they appear. The user can write V or v or vivid or Vivid or write Blue or blue, or B,... (1 Reply)
Discussion started by: Ernst
1 Replies

5. Shell Programming and Scripting

case statement

Hi all, I think i'm asking a sqtupid question here.. i'm using case sttament, what is the syntax or symbol for "or"? I thought was || here a quick sample of my case statment echo "Would you like to update your detail ?" read response case $response in ... (2 Replies)
Discussion started by: c00kie88
2 Replies

6. Shell Programming and Scripting

help with case statement

I am writing a script to pull diskspace information from our servers. Here is the script that I wrote: #!/bin/ksh for host in `cat /oper/hosts/esc.misc` do ssh -q -o ConnectTimeout=10 operator@$host df -h|grep "/dev/" |egrep '8%|9%|100%' | awk '{print H " " "at " $5 " with " $4 "... (1 Reply)
Discussion started by: rkruck
1 Replies

7. Shell Programming and Scripting

case statement

Hi, I am writing case statement to execute some finction, my requirement is once one of the case statement is executed again it has to prompt for the option. for script in `echo "$Script_Selected"` do case $script in 1) getNoOFActUsers ;; 2) moveServerrOORotation ;; ... (2 Replies)
Discussion started by: Satyak
2 Replies

8. Shell Programming and Scripting

Case statement

Hello, The standard case statement :- case "$1" in "IE0263") commands;; "IE0264") commands;; esac is it possible to have :- case "$1" in "IE0263" OR "IE0878") commands;; "IE0264") commands;; esac Thanks (4 Replies)
Discussion started by: jmahal
4 Replies

9. Shell Programming and Scripting

Case Statement

Hey, guys I really need some help with a project. "Write a shell program that examines the command line arguments, counts and collects the number of options. Basically it has to collect and count the arguments that start with a "-" and the one's that don't start with a - I know I have to use... (2 Replies)
Discussion started by: sk192010`
2 Replies

10. UNIX for Dummies Questions & Answers

Case statement help

Hi I am new to shell scripting, I wanted to make a shell script that has a case statement asking the user to select their city 1)london 2)tokyo 3) etc., I then want the users input to be stored in a variable and echoed out in another script; so for example if the user selects tokyo, tokyo city code... (2 Replies)
Discussion started by: scriptnewbie
2 Replies
ID3TOOL(1)						      General Commands Manual							ID3TOOL(1)

NAME
id3tool - a command line editor for id3 tags. SYNOPSIS
id3tool [options] files ... DESCRIPTION
This manual page is for the id3tool command. id3tool is a program that can be used to view and edit id3 tags from the command line. When invoked from the command line with filenames and no options, it will display the used fields of the id3 tags. When invoked from the command line with filenames and "set" options, it will change the id3 tag fields specified to the specified values on all the files. Due to limitations in the ID3v1 specification, most fields are limited to 30 characters. The note field is limited to 28 characters if a track number is in use. You can force a tag to be v1.1 by using a specifying a non-zero track number, or force a tag to be v1.0 by specifying a track number of zero (0). OPTIONS
The programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A complete list of options are included below. For a complete description, use the help option. -t, --set-title=WORD Sets the title to WORD -a, --set-album=WORD Sets the album to WORD -r, --set-artist=WORD Sets the artist to WORD -y, --set-year=YEAR Sets the year to YEAR [4 digits] -n, --set-note=WORD Sets the note to WORD -g, --set-genre=INT Sets the genre code to INT (the codes can be acquired from the genre list.) -G, --set-genre-word=WORD Sets the genre to WORD (given that WORD is from the genre list.) -c, --set-track=INT Sets the track to INT -h, --help Show summary of options. -v, --version Show version of program. -l, --genre-list Shows the genre list. AUTHOR
id3tool and this manual page were written by Chris Collins <xfire@xware.cx> ID3TOOL(1)
All times are GMT -4. The time now is 12:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy