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
to check variable if its non numeric sachin.gangadha Shell Programming and Scripting 3 12-06-2007 05:33 PM
how to check null variable sachin.gangadha Shell Programming and Scripting 2 12-06-2007 04:59 PM
awk: How do i check to see if a variable is a number? natdeamer Shell Programming and Scripting 1 09-06-2007 07:31 AM
How to check a string in the variable josephwong Shell Programming and Scripting 1 06-26-2006 12:14 AM
check for NULL variable esham Shell Programming and Scripting 2 03-20-2005 03:31 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-27-2008
gekkos gekkos is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 2
How to check if a variable contains a .

Hi
I am writing a bash script and would like to check is a variable contains a . or not
ex.
a=102 output ok
a=1.02 output not ok
Many thanks,
  #2 (permalink)  
Old 11-27-2008
Konerak Konerak is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 20
expr index "$a" .

Will check if the variable a contains a .

man expr

to learn more.
  #3 (permalink)  
Old 11-27-2008
gekkos gekkos is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 2
Thanks
  #4 (permalink)  
Old 11-27-2008
Christoph Spohr Christoph Spohr is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 205
Hi,

you could use the build-in test function of bash which supports regexp since version 3.0.

Code:
[[ $a =~ \\. ]] && echo not ok || echo ok
As the dot is a special character you have to escape it.

HTH Chris
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 11:46 PM.


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