I know nothing about bash scripting, but can you use Regular Expressions in bash?
One of the guys I work with wants to write a bash script that will accept a argument or two. *I know to access the args as $1, $2, $N - but how can I check if that argument is a number or a string? I know bash variables are untyped, but if $1 contains a number I want to do one thing if it is a string I want to do another.
I know nothing about bash scripting, but can you use Regular Expressions in bash?
You could use egrep to get your regular expressions:
(untested, but should work).Code:if $(echo $1 | egrep '[0-9]'); then
heh, famous last words, thoseYou could use egrep to get your regular expressions:
(untested, but should work).Code:if $(echo $1 | egrep '[0-9]'); then
That would pass anything that had a mixture of numbers and other stuff. You could change it to
also untested - it might work. :PCode:if $(echo $1 | egrep '^[0-9]*$'); then
Oops, yeah heh
Actually, since you used *, that'll match an empty string, too. You should make it '^[0-9]+$', so that it only matches if there is at least one number. Untested, but it ought to work![]()
Bookmarks