Fw: Unix question

Brian K. White brian at aljex.com
Fri Apr 16 10:30:14 PDT 2004


bahh screwed up and sent it private...
this is "forwarded" from my sent folder

Brian K. White wrote:
> Kenneth Brody wrote:
>> (Top-posting and improper quoting corrected.)
>> 
>> 
>>>>> Thanks.
>>>>> The quotes were not necessary.  Ken's example worked perfectly.
>>>>> I was trying to look for the string rctp(54)=
>>>>> The \ is a escape character (just like in filePro) to tell grep (I
>>>>> guess) that the (  and  ) are part of the string being searched,
>>>> [...]
>>>>>>       grep  rcpt\(54\)= prc.*
>>>> [...]
>>>> 
>>>> If that was your intent, it didn't do what you wanted, since the
>>>> shell sees them first. You need to double them to get one passed
>>>> to the program.
>>> 
>>> Double what?
>>> I wanted: rcpt(54)=
>>> I used the example you gave me and it worked perfectly.
>>> I don't need to see the \
>>> Am I missing something?
>> 
>> You said that the backslashes were "to tell grep that the ( and ) are
>> part of the string being searched".  With the command you wrote, grep
>> will never see the backslashes, as they will be eaten by the shell.
>> If your intention were to pass backslashes to grep, you would have
>> had to double the backslashes.  As written, it is the shell that you
>> are telling to pass the parens to grep, rather than having the shell
>> give them special meaning.  (Or, just put it in quotes, and leave the
>> backslashes off.)
> 
> [this turned into a mini-lecture, and I happen to be replying to a
> post by ken, but I know ken is already familiar with all this so
> please don't think i'm insulting you ken]
> 
> But, perens have no special meaning to grep the way they do the
> shell, so, they only need to be escaped once for the command to do
> what he expected/wanted, which it did.
> 
> If the search string had contained a . then you would also want just 1
> escape in front of that if you really wanted to search for a . and
> not <any single character> because in that case a . has no special
> meaning to the shell, so the shell won't eat it or translate it into
> something else, but it does have special meaning to grep and grep
> will match it with any single character, which will get you the
> string yu were looking for but also any other string that happened to
> be the same except for that one character. IE: if you want to search
> for "plant." and don't escape the . then you will get "plant." and
> "plant," and "plants" and "plant " etc... if any of those happen to
> exist. 
> 
> If the search text had contained [stuff] then you would want 2
> escapes in front of each [ and ], like blah\\[stuff\\]blah,
> because [] has special meanings in both the shell and grep.
> However, at that point it's generally saner and nicer to other
> programmers to instead of using \ to get things past the shell,
> enclose the whole thing in single quotes for '\[stuff\]' if at all
> possible. You can't always do that, like if you need to use a
> variable or some form of shell expansion or globbing within the
> search string, but if you can strip away one whole layer of \'s by
> quoting the whole string it's helpful. 
> 
> Brian K. White  --  brian at aljex.com  --  http://www.aljex.com/bkw/
> +++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
> filePro BBx  Linux SCO  Prosper/FACTS AutoCAD  #callahans Satriani


More information about the Filepro-list mailing list