-   Linux - General (
-   -   grep in shell script fails on redhat 3.0 (

rlangsto 03-06-2005 05:34 PM

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 works / fails

Any thoughts ?

Tinkster 03-06-2005 05:44 PM

The files name wouldn't contain a space by any chance?


rlangsto 03-06-2005 06:45 PM

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.

Tinkster 03-06-2005 07:25 PM

All I can say is that something like

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 ;)


rlangsto 03-06-2005 08:42 PM

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.

All times are GMT -5. The time now is 01:26 AM.