Skip to main content
added syntax from bash
Source Link

The syntax of the case command is:

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

Syntax for case also can be printed in bash by the command below (it is suitable for POSIX shell as well):

$ help case
case: case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac

Execute commands based on pattern matching.

Selectively execute COMMANDS based upon WORD matching PATTERN.  The
`|' is used to separate multiple patterns.

Exit Status:
Returns the status of the last command executed.

Syntax in man bash:

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

can be found by ^ *case pattern.

Example of usage:

time="1m"
case "$time" in
    *h*|*m*|*s*)
        echo "first case"
        echo "handling several cases for h, m, s tokens" ;;
    *)
        echo "seconds case" 
        echo "handling other cases" ;;
esac

References and related questions with examples:

The syntax of the case command is:

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

Syntax for case also can be printed in bash by the command below (it is suitable for POSIX shell as well):

$ help case
case: case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac

Execute commands based on pattern matching.

Selectively execute COMMANDS based upon WORD matching PATTERN.  The
`|' is used to separate multiple patterns.

Exit Status:
Returns the status of the last command executed.

Example:

time="1m"
case "$time" in
    *h*|*m*|*s*)
        echo "first case"
        echo "handling several cases for h, m, s tokens" ;;
    *)
        echo "seconds case" 
        echo "handling other cases" ;;
esac

References and related questions with examples:

The syntax of the case command is:

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

Syntax for case also can be printed in bash by the command below (it is suitable for POSIX shell as well):

$ help case
case: case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac

Execute commands based on pattern matching.

Selectively execute COMMANDS based upon WORD matching PATTERN.  The
`|' is used to separate multiple patterns.

Exit Status:
Returns the status of the last command executed.

Syntax in man bash:

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

can be found by ^ *case pattern.

Example of usage:

time="1m"
case "$time" in
    *h*|*m*|*s*)
        echo "first case"
        echo "handling several cases for h, m, s tokens" ;;
    *)
        echo "seconds case" 
        echo "handling other cases" ;;
esac

References and related questions with examples:

proper disabling highlighting for second syntax block
Source Link

The syntax of the case command is:

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

Syntax for case also can be printed in bash by the command below (it is suitable for POSIX shell as well):

$ help case
case: case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac

Execute commands based on pattern matching.

Selectively execute COMMANDS based upon WORD matching PATTERN.  The
`|' is used to separate multiple patterns.

Exit Status:
Returns the status of the last command executed.

case: case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac

Execute commands based on pattern matching.

Selectively execute COMMANDS based upon WORD matching PATTERN.  The
`|' is used to separate multiple patterns.

Exit Status:
Returns the status of the last command executed.

Example:

time="1m"
case "$time" in
    *h*|*m*|*s*)
        echo "first case"
        echo "handling several cases for h, m, s tokens" ;;
    *)
        echo "seconds case" 
        echo "handling other cases" ;;
esac

References and related questions with examples:

The syntax of the case command is:

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

Syntax for case also can be printed in bash by the command below (it is suitable for POSIX shell as well):

$ help case
case: case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac

Execute commands based on pattern matching.

Selectively execute COMMANDS based upon WORD matching PATTERN.  The
`|' is used to separate multiple patterns.

Exit Status:
Returns the status of the last command executed.

Example:

time="1m"
case "$time" in
    *h*|*m*|*s*)
        echo "first case"
        echo "handling several cases for h, m, s tokens" ;;
    *)
        echo "seconds case" 
        echo "handling other cases" ;;
esac

References and related questions with examples:

The syntax of the case command is:

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

Syntax for case also can be printed in bash by the command below (it is suitable for POSIX shell as well):

$ help case

case: case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac

Execute commands based on pattern matching.

Selectively execute COMMANDS based upon WORD matching PATTERN.  The
`|' is used to separate multiple patterns.

Exit Status:
Returns the status of the last command executed.

Example:

time="1m"
case "$time" in
    *h*|*m*|*s*)
        echo "first case"
        echo "handling several cases for h, m, s tokens" ;;
    *)
        echo "seconds case" 
        echo "handling other cases" ;;
esac

References and related questions with examples:

disabling highlighting for syntax block
Source Link

The syntax of the case command is:

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

Syntax for case also can be printed in bash by the command below (it is suitable for POSIX shell as well):

$ help case
case: case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac

Execute commands based on pattern matching.

Selectively execute COMMANDS based upon WORD matching PATTERN.  The
`|' is used to separate multiple patterns.

Exit Status:
Returns the status of the last command executed.

Example:

time="1m"
case "$time" in
    *h*|*m*|*s*)
        echo "first case"
        echo "handling several cases for h, m, s tokens" ;;
    *)
        echo "handling other"seconds cases"case" ;;
    *)    echo "handling other cases" ;;
esac

References and related questions with examples:

The syntax of the case command is:

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

Example:

time="1m"
case "$time" in
    *h*|*m*|*s*) 
        echo "handling several cases for h, m, s tokens" ;;
    *)
        echo "handling other cases" ;;
    *)
esac

References and related questions with examples:

The syntax of the case command is:

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

Syntax for case also can be printed in bash by the command below (it is suitable for POSIX shell as well):

$ help case
case: case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac

Execute commands based on pattern matching.

Selectively execute COMMANDS based upon WORD matching PATTERN.  The
`|' is used to separate multiple patterns.

Exit Status:
Returns the status of the last command executed.

Example:

time="1m"
case "$time" in
    *h*|*m*|*s*)
        echo "first case"
        echo "handling several cases for h, m, s tokens" ;;
    *)
        echo "seconds case" 
        echo "handling other cases" ;;
esac

References and related questions with examples:

Question asks for POSIX, so use POSIX docs
Source Link
muru
  • 77.9k
  • 16
  • 212
  • 317
Loading
Source Link
Loading