The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to search a word pvr_satya Shell Programming and Scripting 3 08-04-2008 11:24 AM
To find a character immediately following a word The Observer Shell Programming and Scripting 2 07-11-2008 04:21 AM
Convert character in word to CAPS?? vadharah Shell Programming and Scripting 3 04-01-2008 04:44 AM
Change Position of word character cedrichiu Shell Programming and Scripting 6 03-11-2007 10:52 PM
Grep for X character on a word jjoves UNIX for Dummies Questions & Answers 5 08-06-2004 02:14 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-03-2008
Registered User
 

Join Date: Aug 2008
Posts: 26
to search for a particular character in a word

Hi
I would like to accept in a string from user like
username/pwd@dbname
suppose the user does not input @ then i should throw an error that @ symbol missing . How to achieve this

Thanks in advance
Suresh
Reply With Quote
Forum Sponsor
  #2  
Old 10-03-2008
vidyadhar85's Avatar
The Tutor
 

Join Date: Jun 2008
Location: INDIA
Posts: 549
you can use this
Code:
 
echo "enter username and password"
read var
echo "$var"|grep "@" >> /dev/null
if [ $? -ne 0 ];then echo "no \"@\" found";else echo "\"@\" found";fi
Reply With Quote
  #3  
Old 10-04-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,061
Quote:
Originally Posted by vidyadhar85 View Post
you can use this
Code:
 
echo "enter username and password"
read var
echo "$var"|grep "@" >> /dev/null
if [ $? -ne 0 ];then echo "no \"@\" found";else echo "\"@\" found";fi
The use of grep is not necessary i.e
Code:
#!/bin/bash

read -p "Enter username and password: " var
if [[ $var =~ "@" ]]
then
   echo 'found @'
else
   echo 'no @ found'
fi
Reply With Quote
  #4  
Old 10-04-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
the use of regular expression in bash =~ is also not necessary
Code:
 case $input in *@*) 
    echo "there"
    echo "do something here"
    ;;
 esac
Reply With Quote
  #5  
Old 10-06-2008
Registered User
 

Join Date: Aug 2008
Posts: 26
Thanks guys for
Reply With Quote
  #6  
Old 10-06-2008
Registered User
 

Join Date: Aug 2008
Posts: 26
Thanks guys for ur replies
Reply With Quote
  #7  
Old 10-07-2008
Registered User
 

Join Date: Aug 2008
Posts: 26
Sorry for asking late actually i need to check for / also apart from @
I am using
echo "$var"|grep "@" >> /dev/null
as this worked for me

if i do like
echo "$3"|grep "\/*@" >> /dev/null
i am not getting desired result

is there another way
Thanks in advance
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:57 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0