LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 03-06-2005, 05:34 PM   #1
rlangsto
LQ Newbie
 
Registered: Feb 2002
Posts: 7

Rep: Reputation: 0
grep in shell script fails on redhat 3.0


The issue seems to be for a particular environment,
as other linux boxes that I tested this script on worked just fine.

this is the line in question:

abc_string=`grep "abc_value ${string} " ${0}`

$0 returns the script name as the file to search i.e: ./filename

which returns "no such file or directory"

the version of the grep is the same for all machines. I know this
has to be some o/s level issue, but I don't see it in the env.

o/s levels are 2.4.21.9.EL works / 2.4.21.20.EL fails

Any thoughts ?
 
Old 03-06-2005, 05:44 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,000
Blog Entries: 11

Rep: Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893
The files name wouldn't contain a space by any chance?


Cheers,
Tink
 
Old 03-06-2005, 06:45 PM   #3
rlangsto
LQ Newbie
 
Registered: Feb 2002
Posts: 7

Original Poster
Rep: Reputation: 0
Smile

Thanks for the thought, but no .... no space.
keep in mind it works fine on other linux systems.

I thought it might be a literal translation in other words,
it was looking for a file name './<somefile>' but no such luck. I am wondering if the grep command used in a script like this opens it's own thread "exec" , and that thread env is dong starting in $HOME or some such , thus the failure.
looks like it may be time to try strace or truss.
 
Old 03-06-2005, 07:25 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,000
Blog Entries: 11

Rep: Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893
All I can say is that something like
Code:
#!/bin/bash
echo ${0}
abc_string=`grep "echo" ${0}`
echo $abc_string
works ... I accidentally deleted the $ at some stage,
and the {0} gave me the error-message you encounter ;)



Cheers,
Tink
 
Old 03-06-2005, 08:42 PM   #5
rlangsto
LQ Newbie
 
Registered: Feb 2002
Posts: 7

Original Poster
Rep: Reputation: 0
Just an FYI,
the problem was in the environment files that the
script was sourcing when running.
someone had placed a cd "change directory"
so that when I sourced the environment for the shell
script, it set PWD to $HOME instead of where the script was located.

only took about 5 hours to figure it out. Oh well, sometimes you have to do the grunt work.

thanks for your replies, they were sanity checks.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script: grep using string with specail charactors? Chowroc Programming 6 11-14-2005 09:47 PM
Grep Syslog - email shell script voodoofxz Linux - Newbie 1 09-06-2005 05:27 PM
Run shell script in RedHat after boot dmorse Linux - General 1 08-23-2005 02:54 PM
Redhat AS 3, shell/script question Bubba235 Linux - Enterprise 2 10-26-2004 01:15 PM
How do I zip and attach the output data of a grep | awk | mail shell script? 360 Programming 1 05-08-2002 09:26 AM


All times are GMT -5. The time now is 04:20 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration