I trying to use regex expression for a bash if statement.
if [[ "$@" =~ blah blah ]]; then … ; fi
`result expected:
-a (not match: as standalone)
-auto (not match: as standalone)
-lv (not match: no "a" or "--auto")
-l --verbose (not match: no "a" or "--auto")
-v --log (not match: no "a" or "--auto")
-n --make-auto (not match: no "a" or "--auto")
-g --auto-gen (not match: no "a" or "--auto")
-a -l (match: "-a" used with other)
-l -a -v (match: "-a" used with other)
-l -s -a (match: "-a" used with other)
-ls -a (match: "-a" used with other)
-va -s (match: "-a" used with other)
-lav (match: a used with other)
-alva (match: a used with other)
-l --auto (match: "--auto" used with other)
-l --auto (match: "--auto" used with other)
--auto -lv (match: "--auto" used with other)
--auto --log (match: "--auto" used with other)
--auto --log (match: "--auto" used with other)`
I have made so many test and I think that I don't understand anything to regex I have read many tutorials and links found here but if I understand well there is no AND but only OR
`(^[^--auto]$|[[:space:]]--auto[[:space:]]{0,}|^--auto[[:space:]]{1,}[[:graph:]]{1,})
"--log --auto" => OK
"--log --auto --verbose" => OK
"--log --auto-gen" => KO match but need to not match no --auto`
`(^[^--auto]$|[[:space:]]--auto[[:space:]]{1,}|^--auto[[:space:]]{1,}[[:graph:]]{1,})
"--log --auto --verbose" => OK
"--log --verbose --auto" -> KO`
`(^[^--auto]$|[[:space:]]--auto[[:space:]]{1,}$|^--auto[[:space:]]{1,}[[:graph:]]{1,})`
and so on …
with short param now … match anything even if "-a" is alone !
`((^-([a-z0-9])*a{1,}.*)|([[:space:]]-([a-z0-9])*a{1,}.*))
"-a" => KO match and do not need
"-l -a" => OK
"-a -l" => OK
"-la" => OK
"-lv" => OK
"-a -l -v" => OK
"-v -z -a" => OK`
if I add (^-[^a]$)
at the front … no effect
`(^-[^a]$)|((^-([a-z0-9])*a{1,}.*)|([[:space:]]-([a-z0-9])*a{1,}.*))`
and if I mix short and long badaboum !
I may have a workaround by testing params separately but i'm trying to test the whole line.
Is it possible to do this in regex and bash ?
Thanks in advance for your advices and help.