You are not logged in.
Pages: 1
In BASH, how do you check if a parameter is an integer? I've Googled, searched the forums and read a few guides but can't find anything. I would imagine it's a -something option so that I could use if [ -i $1 ] or something along those lines but I can't seem to find anything.
For the strength of the pack is the wolf, and the strength of the wolf is the pack.
Offline
It seems the built in math function $((...)) returns 0 on strings.
var="str"
[ $var != 0 ] && [ $(($var+0)) = 0 ] && echo this is a string.
var="55"
[ $var != 0 ] && [ $(($var+0)) = 0 ] || echo this is an integer.
var="0"
[ $var != 0 ] && [ $(($var+0)) = 0 ] || echo this is an integer.
var="string1with2integers"
[ $var != 0 ] && [ $(($var+0)) = 0 ] && echo this is a string.
seems to work...
Offline
That seems to have done the trick. I thought bash would have something built in for stuff like this but I guess this will work.
Thank you, Gilneas.
For the strength of the pack is the wolf, and the strength of the wolf is the pack.
Offline
Pages: 1