help-bash
[Top][All Lists]
Advanced

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

Re: Option immediately followed by a number


From: Tapani Tarvainen
Subject: Re: Option immediately followed by a number
Date: Mon, 20 Mar 2023 09:02:21 -0500

On Mar 19 20:02, uzibalqa (uzibalqa@proton.me) wrote:

> Have done
> 
> ("-n"+[[:digit:]])
> 
> But there is something wrong with it.

Parentheses in the wrong place. Try this:

shopt  -s extglob

case "$1" in
    -n+([[:digit:]])) echo ok;;
esac


If you want to do it without extglob, you can do something
like this:

case "$1" in
    -n*[^[:digit:]]*) echo bad;;
    -n[[:digit:]]*) echo ok;;
esac

I.e., first exclude cases with non-digits, then require
at least one digit.

-- 
Tapani Tarvainen



reply via email to

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