8

In the Ubuntu 18.04 LT .bashrc file there is the following:

# set a fancy prompt (non-color, unless we know we "want" color) case "$TERM" in xterm-color) color_prompt=yes;; esac 

Isn't xterm-color) an instance of unbalanced parentheses? And why does the line end with two semicolons?

To be clear, this is not something I wrote. It's in the virgin file, not edited by me.

If there are syntax errors, to whom should I report this?

5
  • 11
    There's an easy way to check if this is a syntax error: just run it, and Bash will tell you whether it is a syntax error. In fact, this will be run every time you open a terminal, so you just have to look if there is a syntax error printed every time you open the terminal. Commented Mar 17, 2019 at 7:43
  • 4
    if it's an error then you'll get a report every time you open a new terminal Commented Mar 17, 2019 at 8:42
  • 14
    Prior research might have included simply looking up the syntax for switch/case in Bash, through which you would have quickly discovered that this is entirely normal. Commented Mar 17, 2019 at 16:37
  • 6
    @JörgWMittag If you don't know what a script does, running it might be a not so clever idea. Checking it with bash -n .bashrc is probably better Commented Mar 18, 2019 at 8:36
  • @ChatterOne: It gets executed every single time you open a terminal; if there is something malicious about it, it will already have happened a long time ago. Commented Mar 20, 2019 at 18:22

1 Answer 1

39

This is the standard, correct syntax for a bash case statement(known abstractly as a switch statement in general programming), albeit perhaps an odd syntax when compared to C, Java, or other languages.

From The Linux Documentation Project:

Nested if statements might be nice, but as soon as you are confronted with a couple of different possible actions to take, they tend to confuse. For the more complex conditionals, use the case syntax:

case EXPRESSION in CASE1) COMMAND-LIST;; CASE2) COMMAND-LIST;; ... CASEN) COMMAND-LIST;; esac 
3
  • (the information is also available from help case command.) Commented Mar 17, 2019 at 10:38
  • 4
    There can actually be an optional opening parenthesis in front of any of the patterns, i.e. case $var in (foo) echo something;; esac. Bash's command line help doesn't mention that, but the online reference manual has it (Along with an example case statement, too...) Commented Mar 17, 2019 at 17:55
  • 3
    Not just in bash; the POSIX shell specification allows an optional opening ( as well. Commented Mar 17, 2019 at 22:20

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.