Search code examples
bashshglob

What is the difference between ? and * in Bash?


So you know, you do your standard getopts setup:

while getopts :a:bc option
do
    case "${option}"
    in
        a)
            # do a manditory thing!
        ;;
        b)
            # do a optional thing!
        ;;
        c)
            # for real, you usually would set variables using getopts
        ;;
        ?) # unexpected flag(?)
            echo "FATAL: Unexpected flag ${OPTARG}"
            exit 2
        ;;
        *) # litterally nothing entered(?)
            show_help
            exit 1
        ;;
    esac
done

To my knowledge, ? is for flags other than those defined, and *is for if there are no arguments entered. However, I'm not sure....


Solution

  • Difference between question mark and Asterisk in Bash:

    ?: matches any single character

    *: matches any number of any characters including none

    Source: https://en.wikipedia.org/wiki/Glob_(programming)