Skip to main content
deleted 1 character in body
Source Link
raciasolvo
  • 199
  • 1
  • 5

For unsigned integers I use:

read -r scale [ -z "${scale//[0-9]/}" ] && [ -n "$scale" ] || echo "Sorry integers only" 

Tests:

$ ./test.sh 7 $ ./test.sh 777 $ ./test.sh a Sorry integers only $ ./test.sh "" Sorry integers only $ ./test.sh Sorry integers only 

For unsigned integers I use:

read -r scale [ -z "${scale//[0-9]/}" ] && [ -n "$scale" ] || echo "Sorry integers only" 

Tests:

$ ./test.sh 7 $ ./test.sh 777 $ ./test.sh a Sorry integers only $ ./test.sh "" Sorry integers only $ ./test.sh Sorry integers only 

For unsigned integers I use:

read -r scale [ -z "${scale//[0-9]}" ] && [ -n "$scale" ] || echo "Sorry integers only" 

Tests:

$ ./test.sh 7 $ ./test.sh 777 $ ./test.sh a Sorry integers only $ ./test.sh "" Sorry integers only $ ./test.sh Sorry integers only 
added 3 characters in body
Source Link
raciasolvo
  • 199
  • 1
  • 5

For unsigned integers I use:

read -r scale [ -z "${scale//[0-9]/}" ] && [ -n "$scale" ] || echo "Sorry integers only" 

Tests:

$ ./test.sh 7 $ ./test.sh  777 $ ./test.sh a Sorry integers only $ ./test.sh "" Sorry integers only $ ./test.sh Sorry integers only 

For unsigned integers I use:

read -r scale [ -z "${scale//[0-9]/}" ] && [ -n "$scale" ] || echo "Sorry integers only" 

Tests:

$ ./test.sh 7 $ ./test.sh 777 $ ./test.sh a Sorry integers only $ ./test.sh "" Sorry integers only $ ./test.sh Sorry integers only 

For unsigned integers I use:

read -r scale [ -z "${scale//[0-9]/}" ] && [ -n "$scale" ] || echo "Sorry integers only" 

Tests:

$ ./test.sh 7 $ ./test.sh  777 $ ./test.sh a Sorry integers only $ ./test.sh "" Sorry integers only $ ./test.sh Sorry integers only 
Source Link
raciasolvo
  • 199
  • 1
  • 5

For unsigned integers I use:

read -r scale [ -z "${scale//[0-9]/}" ] && [ -n "$scale" ] || echo "Sorry integers only" 

Tests:

$ ./test.sh 7 $ ./test.sh 777 $ ./test.sh a Sorry integers only $ ./test.sh "" Sorry integers only $ ./test.sh Sorry integers only