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 > 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
redirecting variable content to a file! lloowen Shell Programming and Scripting 2 05-24-2008 04:30 PM
Content of Content of a variable! jaduks Shell Programming and Scripting 2 08-27-2007 12:40 AM
replace a string with content from another file afatguy Shell Programming and Scripting 4 09-14-2006 09:25 PM
How to replace a variable content josephwong Shell Programming and Scripting 4 06-25-2006 11:18 PM
Compare the content of 2 files odogbolu98 Shell Programming and Scripting 3 09-10-2002 11:44 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-31-2005
robdai robdai is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 2
Compare the content of a variable with a string

Hello all:

I'm new in Unix and here and I'am spanish so my english isn't so good to explain my doubt. Here it is.

Very urgent:

I need to compare the value of a variable with a string.
Example is this.

Imagine that the variable x1 contains the path and a file text and I need to compare this with a string to put later with a echo a message

Could you help me?

I need to get only the name of the file without the path and I don't know how to do this. Something like this?

For_prp contains the path: C:\Program_Files\example\A1\prueba.txt and I need to compare with "prueba". Is like this?

if [ `grep -l '*prueba' ${For_prp}` ];
then
echo "The file${For_prp} is form the module of Pruebas"

Than you
  #2 (permalink)  
Old 10-31-2005
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
So you want to check that the file path contains a certain string?

Generally, you can do this by checking the exit status of the grep...

For example:

Code:
$ ( echo "${For_prp}" | grep "preuba.txt" >/dev/null 2>&1) && echo "Yes" || echo "No"
No
$ ( echo "${For_prp}" | grep "prueba.txt" >/dev/null 2>&1) && echo "Yes" || echo "No"
Yes
We can show this in an easier to understand form too:

Code:
echo "${For_prp}" | grep "prueba.txt" >/dev/null 2>&1
if [ "$?" -eq "0" ]; then 
  echo "Yes"
else
  echo "No"
fi
Cheers
ZB
  #3 (permalink)  
Old 11-01-2005
robdai robdai is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 2
Than you very much

thanks a lot
Sponsored Links
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 07:31 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