Wednesday, June 16, 2010

Just in case

I just learned something new about shell syntax -- specifically, about the case statement.

The shell's big enough that I expect I'll be able to keep learning things about it for a long time, even though I've been writing shell scripts for ... lessee ... about 30 years.

Here's today's:

I'm used to writing this:
case $key in
whatever) do-something ;;
*) some-default-behavior ;;
esac
I just read a Fedora system script that looks like this, instead:
case $key in
(whatever) do-something ;;
(*) some-default-behavior ;;
esac
The leading paren is optional, but legal. And not just for bash, but for any POSIX shell. Amazing. Also, the last item doesn't have to have the semis, so it could even be this:
case $key in
(whatever) do-something ;;
(*) some-default-behavior
esac




2 comments:

Anonymous said...

Work For Advertising Company at www.visionjobcare.com

Join one of the best Advertising Company of India. We pay you for your hard work. 100% Payment Assurance. Its a copy-paste work. Unlimited Monthly income.
For more details: E-mail us at support.visionjob@gmail.com Website: http://www.visionjobcare.com/XXX.html

謝佑芝 said...

IS VERY GOOD..............................