In bash shell, how do we judge if a variable is a string or number? Here, number could be an integer or a float. This link "How to judge a variable's type as string or integer" seems to only work integer.
2 Answers
Based on referred question, following does the job for me:
[[ $value =~ ^[0-9]+(\.[0-9]+)?$ ]]
2 Comments
cmbuckley
You'll need to escape the
., otherwise it will match 2c2 and the like.Peter Butkovic
correct, I had it in my post, just seems like it was rendered without it, thanks for remark, updated my solution