0
    [[ $1 =~ .*\d+.* ]] && echo "The name must not contain digits" && exit 1

    echo "Oh no"

This script prints "Oh no" regardless if the first argument contains numeric characters or not. What am I doing wrong?

2
  • 1
    \d is a PCRE extension. ERE (the POSIX regular expression standard) only guarantees [[:digit:]]. If you use \d in bash, it'll work on some operating systems -- where the standard C library's regex functions are extended -- and not others; it's always more reliable to stick to what the standard guarantees. Commented Oct 20, 2020 at 15:19
  • 2
    BTW, =~ doesn't do any implicit anchoring, so just [[ $1 =~ [[:digit:]] ]] will do; no need for the .*s. Commented Oct 20, 2020 at 15:21

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.