Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-09-2010, 02:06 PM   #1
Registered: Jan 2007
Distribution: debian on servers, ubuntu on desktops/laptops
Posts: 45

Rep: Reputation: 16
BASH - regex in a case statement

Hi, the following works and BASH doesn't complain, but VIM highlights the closing square bracket is if it sees a syntax error. Is there a better way to express regex in a case statement or is this an issue with VIM?


  case $1 in
    [zZ] ) echo "you said z or Z";;
Old 06-09-2010, 02:42 PM   #2
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,388
Blog Entries: 15

Rep: Reputation: 1406Reputation: 1406Reputation: 1406Reputation: 1406Reputation: 1406Reputation: 1406Reputation: 1406Reputation: 1406Reputation: 1406Reputation: 1406
Is it highlighted only when you're on it or the open bracket? Vim likes to highlight matching pairs like that. On my system I see it highlight both the open and the close when I'm on either - there is a difference in the bold for the one I'm on as opposed to its match but both are highlighted.

Last edited by MensaWater; 06-09-2010 at 02:47 PM.
Old 06-09-2010, 03:30 PM   #3
Registered: Jan 2007
Distribution: debian on servers, ubuntu on desktops/laptops
Posts: 45

Original Poster
Rep: Reputation: 16
Yes, same here. When a bracket is selected, VIM highlights it with a flashing yellow/teal and the matching bracket with teal, but in this case it's highlighting the closing square bracket in red, without the opening or closing square brackets selected.

I've seen this before when I'd use a bashism in a script that starts with #!/bin/sh instead of #!/bin/bash so it definitely looks like it's trying to alert me to a syntax error..

Last edited by akelder; 06-09-2010 at 03:36 PM.
Old 06-09-2010, 04:02 PM   #4
Senior Member
Registered: Jul 2005
Distribution: Slackware
Posts: 2,014

Rep: Reputation: 115Reputation: 115
Vim can occasionally get syntax highlighting wrong. Shell is definitely not the easiest language to parse.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
escape '*' in case statement bash junust Programming 2 01-23-2010 03:54 AM
[SOLVED] BASH --> esc key in a case statement manwithaplan Linux - Newbie 6 10-05-2009 10:33 PM
Pattern matching in a bash case statement using regex ciphyre Programming 1 01-31-2009 12:20 PM
bash case statement with multiple command line options pwc101 Programming 16 06-01-2007 11:43 AM
Pattern matching with a "case" statement in BASH King V Programming 8 04-27-2006 04:19 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:06 AM.

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