Bash-common-checks: Difference between revisions

From I Will Fear No Evil
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
#Common checks and validations that are a PITA to remember#
===Common checks and validations that are a PITA to remember===
* Check if a var is an integer
* Check if a var is an integer
* support negative as well as positive integer values using extended regex
<pre>
<pre>
VAR=123
VAR=123

Revision as of 13:20, 19 October 2021

Common checks and validations that are a PITA to remember

  • Check if a var is an integer
  • support negative as well as positive integer values using extended regex
VAR=123
if [[ ${VAR} =~ ^-?[0-9]+$ ]]; then
  echo "Is integer"
else
  echo "Is not integer"
fi