LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-19-2018, 01:59 PM   #1
bkelly
Member
 
Registered: Jan 2008
Distribution: Centos 7-4
Posts: 205

Rep: Reputation: 13
bash case and unmatched parens


I am a bit surprised to not see a forum for scripting, maybe one for each shell. This is probably a newbie question so it goes here.

While checking out the case statement I see that case values are terminated by an close parenthesis. An unbalanced close parenthesis. And none of the places I have visited mention this oddity.

REALLY!?! Couldn't use something that does not come in matching pairs, like a colon?

This will cause problems with editors that help find matching parens, braces, and brackets.

Don't forget, I am very much a newbie.
 
Old 01-19-2018, 02:16 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
Stroll on over to the Programming forum where you will find members eager to help with all programming questions, including shell scripting!

The unmatched parenthesis syntax of the shell case statement is simply that, a syntax construct with historical roots in an earlier language as I recall. It is often commented on, and perhaps an oddity in comparison to other languages and human habits, but it works and is what it is - a syntax tool to be used by the programmer!

Last edited by astrogeek; 01-19-2018 at 02:16 PM. Reason: typo
 
Old 01-19-2018, 02:28 PM   #3
bkelly
Member
 
Registered: Jan 2008
Distribution: Centos 7-4
Posts: 205

Original Poster
Rep: Reputation: 13
I was thinking that scripting is different from programming, but that is cool. I will use it next time.
I found a couple of tutorials on bash and the case statement and nothing was said about that oddity.
Thank you for taking the time to reply.
 
Old 01-19-2018, 06:53 PM   #4
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,152

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
A decent text editor with syntax highlighting will handle the case statments with no trouble.
 
1 members found this post helpful.
Old 01-19-2018, 08:11 PM   #5
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,805

Rep: Reputation: 1206Reputation: 1206Reputation: 1206Reputation: 1206Reputation: 1206Reputation: 1206Reputation: 1206Reputation: 1206Reputation: 1206
The umatched parens even caused a parser problem in bash <=3 and ksh88 concerning $(subshell).
Fortunately solved in bash 4 and ksh93.
But there has been a work-around: simply add the opening parenthesis!
Code:
case $x in ( [Yy]* ) echo "$x starts with Y";; esac
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
vim C/C++ highlight parens, brackets? Tachtory Linux - Software 3 01-24-2014 04:28 AM
[SOLVED] Java System.out.println(); Issues. Compiler thinks not enough close parens Djyou Programming 2 11-22-2013 05:05 PM
[SOLVED] Bash: Checking for lower case and upper case letters in a string fatalerror0x00 Programming 1 12-09-2012 02:17 AM
Parens after commands downinthemine Linux - General 9 05-28-2004 06:57 AM
bash'ed by case statement??? 3inone Programming 2 04-29-2004 04:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration