0

How can I negate the expression as the following matches a numeric check.

  elif [[ $pn =~ ^[[:digit:]]+$ ]]; then
    pfm -w "pn failed numeric inspection"

1 Answer 1

1

You may negate the test using

[[ ! $pn =~ ^[[:digit:]]+$ ]]

or, in this case,

[ -z "$pn" ] || [[ $pn =~ [^[:digit:]] ]]

i.e., "is $pn empty or does it contain a non-digit?"

Or, with a globbing test,

[ -z "$pn" ] || [[ $pn == *[![:digit:]]* ]]

or, using an extended globbing pattern,

[[ $pn != +([[:digit:]]) ]]
1
  • Or: ! [[ .... may also work.
    – user232326
    Commented Jul 27, 2021 at 1:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .