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
Grep help flood Shell Programming and Scripting 3 06-06-2008 01:14 AM
Grep Aejaz UNIX for Advanced & Expert Users 3 04-30-2008 07:10 AM
grep dineshr85 Shell Programming and Scripting 1 10-10-2007 04:52 AM
how to exclude the GREP command from GREP yamsin789 UNIX for Advanced & Expert Users 2 10-05-2007 02:59 AM
Make grep -c display like grep -n? Jerrad Shell Programming and Scripting 2 08-25-2006 12:20 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-18-2007
useless79 useless79 is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 57
help in grep

hi all,


could any one tell me what is diffrence in using " " and ' ' in grep.
eg what is diff in the following


grep "ram" filename

grep 'ram' filename
  #2 (permalink)  
Old 09-18-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
You will not find any difference between those two grep's. Rather try these two and see the difference.

grep '$USER' /etc/passwd
grep "$USER" /etc/passwd

Open the man pages of sh or ksh and see the section on Quoting. Basically single quotes prevent variable expansion.
  #3 (permalink)  
Old 09-18-2007
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Lightbulb

Quote:
Originally Posted by vino View Post
You will not find any difference between those two grep's. Rather try these two and see the difference.

grep '$USER' /etc/passwd
grep "$USER" /etc/passwd

Open the man pages of sh or ksh and see the section on Quoting. Basically single quotes prevent variable expansion.
Adding to Vino's comment...
variables in single quotes are treated as const. string

as
1. var = 5 ;
echo '$var'

This will simply display the string $var as it is, no variable replacement by value.

2. var = 5;
echo "$var"
In double quotes variables get expansion in terms of its value.
o/p will be 5


Similarly is the case with grep '$var' and grep "$var".
But when it comes to constant string, it hardly reflects any change.

grep -w "string1 string2" file1
grep -w 'string1 string2" file1

Both are same.

Hope you get this !!
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 04:48 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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