The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #6 (permalink)  
Old 08-29-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Put the case-esac construct in a while loop.


Code:
[/tmp]$ cat test.ksh
#! /bin/ksh
#

while :
do
    case $1 in
        "") set -- a ;;
        "a") echo "a" ; set -- b ;;
        "b") echo "b" ; set -- c ;;
        "c") echo "c" ; set -- d ;;
        "d") echo "d" ; break ;;
        *) echo "Wrong" ; break ;;
    esac
done
[/tmp]$ ./test.ksh
a
b
c
d
[/tmp]$ ./test.ksh a
a
b
c
d
[/tmp]$ ./test.ksh c
c
d
[/tmp]$ ./test.ksh d
d
[/tmp]$ ./test.ksh z
Wrong
[/tmp]$ ./test.ksh abcd
Wrong
[/tmp]$