how can i check whether variable contains only character from a-z or A-Z....if my variable contains any alpha numeric, numeric or any character with some special one i.e. *%&@! etcetera etcetera....then it should show me please enter only characters......
Let my variable
var1="abc77}|"
then it should show me "please enter valid character"
hey vino..thanx a lot.......
but neither of the commands are working perfectly for me........in bash
thing is i should allow only those variable which are string...i.e. contains only character....
Those links were meant to be a starting point. I think you understood the code snippets in each. Try to write one based on your understanding. And the when you face an issue, post the code you have so that we can help you better.
hey....vino.....
if i could able to solve on my own..i sudn't post it here....
so help me out...i tried each post provided in replied to this post by you.....but fortunately ya unfortunately...i didn't find a single method..which will help me out in bash .......if you could help me , then please.....
while implying this one....+([a-zA-Z]) , ?(+|-)+([0-9]) and *([0-9]|[a-zA-Z])*...i am getting
-bash: syntax error in conditional expression: unexpected token `('
-bash: syntax error near `+(['
hey.......i did the same thing before posting this let me clear one more time...not successful.......only i sud display abc......
is there any way to find only alphabets.....
for your satisfaction....
[:alpha:] := all letters including digit too
so i request you please go thru the query/questions.....where i clearly mentioned i need only character sets......even though my variable has alphanumeric/numeric/ i sud say please enter valid characters
for sample in abc 123 abc123
> do
> sample_test=`echo $sample | awk '/[[:digit:]]|[[: punct:]]/ { print -1}'`
> if [ "$sample_test" = "-1" ]
> then
> echo "$sample is not valid."
> else
> echo "$sample is valid."
> fi
> done
abc is valid.
123 is not valid.
abc123 is not valid.
if not work properly.
please try this. ++3+3 and 1-a4-- are valid.
#! /bin/ksh
for sample in -abc 123 abc123 ++3+3 1-a4--
do
sample_test=`echo $sample | awk '/[:digit:]|[: punct:]/ { print -1}'`
if [ "$sample_test" = "-1" ]
then
echo "$sample is not valid."
else
echo "$sample is valid."
fi
done