eolas/Programming_Languages/Shell/Case_statements_in_Bash.md
2023-02-21 07:34:13 +00:00

402 B

categories tags
Programming Languages
shell

Case statements in Bash

function convertCharToInt {
    case $1 in
        A | X )
            echo 1
        ;;

        B | Y )
            echo 2
        ;;

        C | Z )
            echo 3
        ;;
        *)
            echo 0
        ;;
    esac
}

Usage:

declare -i intValue = $(convertCharToInt B)