4

In a script /etc/network/if-up.d/avahi-autoipd in my system, I find statements like this:

case "$ADDRFAM" in
  inet|NetworkManager) ;;
  *) exit 0
esac

case "$METHOD" in
static|dhcp|NetworkManager) ;;
*) exit 0
esac

The pipe character | seems like the logic "or", but I can't find this rule in the guide. I can only find | used as the command pipe and the "bitwise or" for the arithmetic integer.

Can anyone tell me what's the usage in this case?

2
  • It is called 'vertical bar character', not 'pipe character'. Commented Aug 8, 2013 at 7:41
  • 1
    @uprego It is called 'vertical line', not 'vertical bar character'. Commented Aug 8, 2013 at 16:43

1 Answer 1

10

In the pattern clauses of a case statement, | means precisely or.

From the bash manual on case:

The syntax of the case command is:

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

The ‘|’ is used to separate multiple patterns, and the ‘)’ operator terminates a pattern list.

2
  • So as I understand it, it's used as the or only in the patterns, right? Commented Aug 8, 2013 at 8:16
  • @platinor: In arithmetic expansions ($((...)) or, in bash and some other shells, the command ((...))), | is the "bitwise-or" operator. (Eg. echo $((18|3)) outputs 19). In bash, if the extglob shell option is enabled (as by default), then | may be used in an "extended glob" pattern to indicate alternation ("or"). See gnu.org/software/bash/manual/bashref.html#Pattern-Matching Commented Aug 8, 2013 at 16:03

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.