LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Cannot run commands in a while read line do loop (https://www.linuxquestions.org/questions/linux-newbie-8/cannot-run-commands-in-a-while-read-line-do-loop-4175541882/)

johnny_t52 05-07-2015 10:33 AM

Cannot run commands in a while read line do loop
 
I am looping through a file and then want to run some commands. Below is my code.

cat $PATHNAME | while read line;
do
PATH=$line
ls -t $PATH/javacore* >$NDIR
diff -w $ODIR $NDIR > $CHGS
done
This is the error I get.
./java_snap_monitor.sh: line 13: ls: command not found
./java_snap_monitor.sh: line 14: diff: command not found

suicidaleggroll 05-07-2015 10:53 AM

Quote:

PATH=$line
You overwrote your PATH environment variable, so the system doesn't know where to look for commands any more. One of the several reasons why generic variables in scripts should not use all caps. Not only do they look like environment variables when they're not, if you do happen to have an environment variable of the same name it will be replaced.

johnny_t52 05-07-2015 11:01 AM

That was the problem. Thank you!

Keith Hedger 05-07-2015 06:50 PM

Please use code tags to make your posts easier to read and also don't forget to mark the thread as solved.


All times are GMT -5. The time now is 09:35 AM.