Member Avatar for cristi2008

hy!
I would like to know how can i ckeck the input if its a number or if its a text?

Recommended Answers

All 3 Replies

Hey there,

This will tell you if your variable is text (a through z) - so your else would cover everything else :)

[[ "$variable" == +([a-zA-Z]) ]] && echo "$variable is character"

just put that in whatever if-else or other testing construct you want and you should be good :)

, Mike

hey eggi, can you elaborate on why you would use the double [[ ?

the standard test is with single [, isn't it?

I mean something like
[$var -eq [a-zA-Z]] && echo '$var is a string'

Hey,

No problem :) The double brackets aren't necessary - I just use those since they make use of the shell's built-in test rather than calling the external test program. Either way works and the difference in cost (time, etc) is neglible for the most part. Just a habit. Of course, in bourne of POSIX shell, the code wouldn't work, while the single bracket test would :)

, Mike

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.