dan9er
dan9er

Reputation: 389

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....

Upvotes: 2

Views: 772

Answers (1)

Cyrus
Cyrus

Reputation: 88563

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)

Upvotes: 4

Related Questions