The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




Thread: help in grep
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #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 !!