LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-13-2006, 03:56 AM   #1
BiThian
Member
 
Registered: Aug 2006
Location: Romania
Distribution: NetBSD 3.1
Posts: 118

Rep: Reputation: 15
Why necessarily " " ?


I was looking for the lines that begin with MANPATH (not MANPATH_MAP!) in the file man.conf.When I entered:
Code:
grep ^\<MANPATH\> /usr/lib/man.conf
, I didn't get any output.But when I tried:
Code:
 grep "^\<MANPATH\>" /usr/lib/man.conf
it worked. What was the problem with my first snippet code?
Thanks!
 
Old 09-13-2006, 04:23 AM   #2
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
The shell will interpret special characters unless you escape them (with \) or enclose them in quotes.

For example, the command:
Code:
echo *
Will print the contents of the current directory, because the shell will evaluate the * and replace it with each file in the current directory (seperated by white space, of course).

While the command:
Code:
echo "*"
Simply prints *

You should look at the bash manpage. There is a section about this called "quoting".

Last edited by zhangmaike; 09-13-2006 at 04:25 AM.
 
Old 09-13-2006, 04:44 AM   #3
BiThian
Member
 
Registered: Aug 2006
Location: Romania
Distribution: NetBSD 3.1
Posts: 118

Original Poster
Rep: Reputation: 15
Yes, I know the quoting problem, but this is what I don't understand:
Code:
grep ^MANPATH /usr/lib/man.conf
-I get output-
Code:
grep "^MANPATH" /usr/lib/man.conf
-I get the same output-
Why doesn't happen the same when I enter the commands from my first post?

Last edited by BiThian; 09-13-2006 at 04:45 AM.
 
Old 09-13-2006, 04:50 AM   #4
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
If you try:
Code:
echo ^MANPATH
The output is:
Code:
^MANPATH
The ^ character has no special meaning.

In your first post, you were using \>

The > is a special character (used with pipes). The shell will see the \ and assume that you meant to escape the > character, not that you're using grep regular expression syntax.

See for yourself using the arguments for grep from your first post. Try:
Code:
echo ^\<MANPATH\>
(the output is ^<MANPATH>)

Code:
echo "^\<MANPATH\>"
(the output is ^\<MANPATH\>)
 
Old 09-13-2006, 04:53 AM   #5
BiThian
Member
 
Registered: Aug 2006
Location: Romania
Distribution: NetBSD 3.1
Posts: 118

Original Poster
Rep: Reputation: 15
What can I say...A big "Thanks"!
 
Old 09-13-2006, 04:56 AM   #6
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
you\'re\ welcome

Last edited by zhangmaike; 09-13-2006 at 05:00 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 02:03 AM
what is "sticky bit mode" , "SUID" , "SGID" augustus123 Linux - General 10 08-03-2012 05:40 AM
Telling people to use "Google," to "RTFM," or "Use the search feature" Ausar General 77 03-21-2010 12:26 PM
"Xlib: extension "XFree86-DRI" missing on display ":0.0"." zaps Linux - Games 9 05-14-2007 04:07 PM
Any way to get "Alice"; "Call of Duty" series and "Descent 3" to work? JBailey742 Linux - Games 13 06-23-2006 02:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration