The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Korn: How to loop through a string character by character shew01 Shell Programming and Scripting 10 12-02-2008 07:58 AM
bash script to check the first character in string ole111 Shell Programming and Scripting 2 03-19-2008 12:34 AM
read string, check string length and cut ozzy80 Shell Programming and Scripting 9 03-21-2007 05:56 PM
converting character string to hex string axes High Level Programming 5 09-20-2006 01:04 PM
how to check first character in var's value. yongho UNIX for Dummies Questions & Answers 7 07-01-2005 11:22 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-05-2007
manas_ranjan's Avatar
manas_ranjan manas_ranjan is offline
Registered User
  
 

Join Date: Jul 2007
Location: Amsterdam
Posts: 177
how to check string of character

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"
  #2 (permalink)  
Old 10-05-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Here are a couple of threads which turned up using the search feature. Do use the search feature.

How to check whether a string is number or not
String Validation program
ksh : find value type
  #3 (permalink)  
Old 10-05-2007
manas_ranjan's Avatar
manas_ranjan manas_ranjan is offline
Registered User
  
 

Join Date: Jul 2007
Location: Amsterdam
Posts: 177
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....
  #4 (permalink)  
Old 10-05-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by manas_ranjan View Post
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.
  #5 (permalink)  
Old 10-05-2007
manas_ranjan's Avatar
manas_ranjan manas_ranjan is offline
Registered User
  
 

Join Date: Jul 2007
Location: Amsterdam
Posts: 177
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 `+(['


any idea......????
  #6 (permalink)  
Old 10-05-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by manas_ranjan View Post
hey....vino.....
if i could able to solve on my own..i sudn't post it here....
When you face an issue, you show us what you tried, the error that you got and then we would be in a better shape to help you out.

Anyway, this should get you started.

Code:
[/tmp]$ cat try.sh
#! /bin/sh

for sample in abc 123 abc123
do
    if [[ $sample == *[[:alpha:]]* ]] ; then
        echo $sample
    fi;
done
    
[/tmp]$ ./try.sh
abc
abc123
[/tmp]$
I leave the rest to you as an exercise. Look under the section 'Pattern Matching' in the man pages of bash for other character classes.

Last edited by vino; 10-05-2007 at 08:50 AM.. Reason: revised.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0