2

http://ss64.com/bash/case.html SHOWS

case word in [ [(] pattern [| pattern]...) command-list ;;]... esac

What are square brackets indicating? Other websites omit them (i.e. no [[(] etc.)

http://www.thegeekstuff.com/2010/07/bash-case-statement/ shows this: no use of [[(] etc.

case expression in
    pattern1 )
        statements ;;
    pattern2 )
        statements ;;
    ...
esac

Thanks for the detailed responses below. I am extremely appreciative of the clarification.

7

Read the authoritative source: the GNU bash manual
https://www.gnu.org/software/bash/manual/bashref.html#Conditional-Constructs

The square brackets indicate optional stuff.

The only mandatory parts are: case word in esac -- this is valid bash that happens to do nothing.

| improve this answer | |
4

Square brackets are a common convention in documentation to indicate that what is inside the bracket is optional. They are part of the metasyntax used by the documentation.

The ... notation is also metasyntax; it indicates that the preceding element may be repeated.

Other common metasyntax include parentheses for grouping and | to mean “or”. Here, it happens that the parentheses and vertical bar are all part of the syntax, whereas the square brackets are all part of the metasyntax.

Good manuals typeset metasyntax in a different font from the syntax. Neither the webpage that you're reading nor the bash manual that it plagiarizes do so in their description of the case command. The bash manual typesets the words word, pattern and command-list in italic; this is also metasyntax, indicating that these words are a description of what goes at this position, rather than words to be typed literally like case, in and esac.

    case word in [ [(] pattern [| pattern]...) command-list ;;]... esac

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.