LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   grep in shell script fails on redhat 3.0 (https://www.linuxquestions.org/questions/linux-general-1/grep-in-shell-script-fails-on-redhat-3-0-a-298446/)

rlangsto 03-06-2005 04: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 2.4.21.9.EL works / 2.4.21.20.EL fails

Any thoughts ?

Tinkster 03-06-2005 04:44 PM

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


Cheers,
Tink

rlangsto 03-06-2005 05: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 06:25 PM

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

rlangsto 03-06-2005 07: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 07:17 PM.