help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Conditional actions according to user input


From: uzibalqa
Subject: Re: Conditional actions according to user input
Date: Sun, 23 Apr 2023 21:39:56 +0000

Have been working on an implementation using a case statement.

For the value, I extract the digit part ("-p([[:digit:]])+" "-q([[:digit:]])+")
or else use arg2 as the value for isolated predicates ("-g")

pary=( "-p([[:digit:]])+" "-q([[:digit:]])+" "-g")

for gpn in "${pary[@]}" # Loop through possible short options
do

case $arg1 in
($gpn) _vl="${arg1:2}" ;; # fill _vl for form -[[:alpha:]]+([[:digit:]])
($gpn) _vl="${arg2}" ;; # fill _vl for form -[[:alpha:]]
(*) _vl="" ;; # fill _vl otherwise
esac

done
------- Original Message -------
On Sunday, April 23rd, 2023 at 9:22 PM, alex xmb ratchev <fxmbsw7@gmail.com> 
wrote:

> i made some args styles demos some ago ..
>
> take a look ..
>
> greets
>
> On Sun, 23 Apr 2023, 6:28 am uzibalqa, <uzibalqa@proton.me> wrote:
>
>> I have a set of possible user input formats stared in an array
>>
>> For instance
>>
>> pary=( "-p+([[:digit:]])" "-g+([[:digit:]])" "-q" )
>>
>> I then want to match these with the actual user inputs
>>
>> for gpn in "${pary[@]}"
>> do
>> if [[ "$arg" == $gpn ]]; then
>>
>> What I do after is dependent on whether the user used the digit form (e.g 
>> "-p+([[:digit:]])")
>> or the isolated predicate form (e.g. "-q").
>>
>> How can I handle the aforementioned functionality in a clear and compact way?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]