I want to be able to extract a flag (-q) and its value from a string. An example:
<string1> -q <value> <string2>
Here, <string1>
and <string2>
can contain any set of characters. To clarify <string1>
and <string2>
are placeholders for any possible string.
I want two things:
- Be able to get the string
<string1> <string2>
- Be able to get the string
<value>
I would also be able to do something similar for this input:
<string1> --all <string2>
where --all
is extracted and <string1> <string2>
is is kept.
Unlike the proposed solution in How do I parse command line arguments in Bash?, I want to be able to extract a flag and its value and then keep the original command line input without the flag and that value.