H
H
HeroFromEarth2017-02-06 16:07:08
linux
HeroFromEarth, 2017-02-06 16:07:08

How to handle getting a param=value parameter in bash?

Hello.
I need to make a script that accepts --enable-all and --birds=5 parameters, while the parameters can be passed in any order.
I process the first one like this:

for PARAM in [email protected]; do
        case $PARAM in
                --enable-all)
                        EnableAll=1 ;;
                --enable-toster)
                        EnableToster=1 ;;
                -h|--help)
                        SHOW_HELP ;;
        esac
done

How to process the second, i.e. to take values ​​of transferred parameters?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
uvelichitel, 2017-02-06
@HeroFromEarth

Try

for PARAM in [email protected]; do
        case $PARAM in
                -ea=* | --enable-all=*)
                        ENABLEALL = "${i#*=}"
                        shift
                        ;;

The construction "${i#*=}"is roughly equivalent`sed 's/[^=]*=//' <<< "$i"`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question