bash check if variable is a number
# bash check if $1 is an integer
# compact version:
[ -n "$1" ] && echo "\$1 : is EMPTY" && exit 1
[ "$1" -eq "$1" ] 2>/dev/null && echo "$1 : is a number" || echo "$1 : not a number"
# long version
if [ "$1" -eq "$1" ] 2>/dev/null; then
echo "$1 : is a number"
else
[ -n "$1" ] && echo "$1 : is EMPTY" && exit 1
echo "$1 : not a number"
fi
re='^[0-9]+$'
if ! [[ $yournumber =~ $re ]] ; then
echo "error: Not a number" >&2; exit 1
fi
Also in C++:
- bash check if variable is a number
- debian install java
- git view remote url
- check postgres version in ubuntu
- facebook signin does not working on facbook app works only when no app is installed
- setting the upstream for a fork github
- git username
- How to use Github Personal Access Token in Jenkins
- take clone from gitbash
- bash how to use screen
- cmdchange directory with space
- find saved wifi password in linux
- find folder linux
- sed tab to space
- youtube-dl ubuntu
- fatal: Not a git repository (or any of the parent directories): .git
- install sdl2 linux
- build.ps1 fie cannot be loaded the file is not digitally signed you cannot run this script on the current system
- list commands in shell
- copier un répertoire et son contenu sous linux
- systemctl status apache2.service
- ubuntu large text
- git hub nvm
- how to install things with apt