E
E
ettaluni2021-08-02 10:39:40
bash
ettaluni, 2021-08-02 10:39:40

How to implement parsing of parameters entered in an arbitrary order?

Good day. I am writing my function in bash, but how to implement free parameter input? So that I can, for example, enter:

command --param1=1 --param2=2 --param3
command --param3=2 --param1 --param2=3

//и.т.п то есть ввод параметров в случайной последовательности

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
AVKor, 2021-08-02
@ettaluni

Here .
If you need semi-automatic mode: here .

X
xotkot, 2021-08-02
@xotkot

https://devhints.io/bash
Getting started options

while ; do case $1 in
  -V | --version )
    echo $version
    exit
    ;;
  -s | --string )
    shift; string=$1
    ;;
  -f | --flag )
    flag=1
    ;;
esac; shift; done
if ; then shift; fi

an example when options are passed to a script with a parameter (-s | --string) and without (-V | --version and -f | --flag), we edit for ourselves

V
Viktor Taran, 2021-08-02
@shambler81

https://solutics.ru/linux/kak-peredat-argumenty-sk...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question