To check if a variable is a positive integer
, I'm resorting to a regular expression:
#!/bin/bash
id="$1"
regNumTest='^[0-9]+$'
if ! [[ "$id" =~ $regNumTest ]]; then
echo "Parâmetro #1 deverá ser um inteiro!"
exit 0
fi
Will it be the best approach to address this issue or can we simplify the process and avoid regular expressions?