1

OS: AIX 7.1
I am working on a shell script which let user input some command and execute it, one of the commands is in this form:

compile appname

the appname only can be one of [ccms|asws], what's the right pattern to match it in case statement ?

here is my shell script:

while true
do
 read cmd
 case $cmd in
 "compile(\s)(ccms)|(asws)") compile
  ;;
 *) break
  ;;
 esac
done

compile(){
 ...
}
2
  • It's very hard to understand the ksh manual for me, my english is very poor. So I just asked here, as I need to finish my job as soon as possible Jul 11, 2014 at 9:05
  • So your shell is ksh? If so, please clarify that in the question.
    – terdon
    Jul 11, 2014 at 9:42

2 Answers 2

1

Let the read command to the splitting.

read cmd arguments
case $cmd in
  compile)
    …
    ;;
esac
0
0

This should work in any POSIX-compliant shell:

case $cmd in
    "compile ccms"|"compile asws") compile
    ;;
    *) break
    ;;
esac

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .