LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   BASH - regex in a case statement (https://www.linuxquestions.org/questions/programming-9/bash-regex-in-a-case-statement-813202/)

akelder 06-09-2010 02:06 PM

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?

Code:

#!/bin/bash

  case $1 in
    [zZ] ) echo "you said z or Z";;
  esac


MensaWater 06-09-2010 02:42 PM

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.

akelder 06-09-2010 03:30 PM

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..

tuxdev 06-09-2010 04:02 PM

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


All times are GMT -5. The time now is 08:46 AM.