![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| Deleteing one character after an special character | mohsin.quazi | Shell Programming and Scripting | 1 | 4 Weeks Ago 04:27 PM |
| Special character \ | amit_arora | Shell Programming and Scripting | 7 | 09-10-2009 07:36 AM |
| check for a particular character inside a file and substitute with a given character? | karthikprasathk | AIX | 1 | 07-01-2008 03:29 AM |
| Special Character Check in Shell script | mradul_kaushik | Shell Programming and Scripting | 1 | 03-24-2006 05:54 PM |
| special character ? | mile1982 | High Level Programming | 1 | 10-19-2004 08:15 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
How to check for special character in a value
Hi,
I have a variable and to it always alphanumeric value will be assigned. If the value has any special characters in it then in the if statement it should exit like below if (value has any speacial character) then exit else .... fi can any one suggest how to acheive this? |
|
||||
|
Did not work for me , might be the issue with the shell
![]() how ever with out negate worked fine. Code:
TES>var=1234; [ ! $(echo $var | grep "[^0-9]") ] && echo $var sh: test: Specify a parameter with this command. Code:
TES>var=1234a; [ $(echo $var | grep "[^0-9]") ] && echo $var 1234a |
|
||||
|
Quote:
Code:
var='1234a;'
if [ ! -z ${var//[[:alnum:]]/} ]
then
exit
else
echo OK; # Do something here
fi
|
|
||||
|
hi,
thanks. It worked for me.. I have to add one condition while checking for the special characters. That is if there is any comma then it should go to else part. if there is any other special characters other than comma then the script has to exit. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|