Case statement - continue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Case statement - continue
# 1  
Old 03-08-2017
Case statement - continue

I have a case statement. IS "continue" working in case?

Code:
 for file in ls dir/*
  
 case $file in
      a)
            do something
            continue
       ;;
       b)
            do something
            continue
       ;;
 esac

It is a Bourne shell
# 2  
Old 03-08-2017
You're missing the "done" at the end, but yes, "continue" works properly inside case.

Example:

Code:
for X in a b c d e
do
        case "$X" in
        a) ;;
        b) ;;
        c) ;;
        d) continue ;;
        e) ;;
        esac

        echo "$X"
done

prints
Code:
a
b
c
e

...since the continue for "d" skips the echo by going straight back to the top.
# 3  
Old 03-08-2017
I need continue after each case in
# 4  
Old 03-08-2017
Quote:
Originally Posted by digioleg54
I need continue after each case in
You don't need a continue after every case. You only need a continue if you want it to skip up to the top of the loop instead of running things after esac. continue is a control for the loop, not for case.

See my example.
# 5  
Old 03-08-2017
That is what I need
Code:
 for file in ls dir/*
do
 case $file in
     a)
        do something
         continue
        ;;
     b)
        do something
         continue
        ;;
  esac
       do something else
done

Will this works?
# 6  
Old 03-08-2017
For that, you can do:

Code:
case "$X" in
a) something ;;
b) something else ;;
*) whatever else ;;
esac

This User Gave Thanks to Corona688 For This Post:
# 7  
Old 03-08-2017
No, it show me an error
Code:
./sftp_ondemand.sh[95]: syntax error at line 324 : `else' unexpected


Last edited by digioleg54; 03-08-2017 at 03:43 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. UNIX for Dummies Questions & Answers

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... (3 Replies)
Discussion started by: msb65
3 Replies

6. 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

7. 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

8. 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

9. 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
Login or Register to Ask a Question