LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-07-2015, 11:33 AM   #1
johnny_t52
LQ Newbie
 
Registered: May 2015
Posts: 2

Rep: Reputation: Disabled
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
 
Old 05-07-2015, 11:53 AM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,552

Rep: Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112
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.
 
1 members found this post helpful.
Old 05-07-2015, 12:01 PM   #3
johnny_t52
LQ Newbie
 
Registered: May 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
That was the problem. Thank you!
 
Old 05-07-2015, 07:50 PM   #4
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,468

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


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH: Read entire file line in for loop clinton Programming 16 04-18-2013 01:06 PM
[SOLVED] while read loop is not looping. Removing a line with an awk command corrects this. amshone Programming 4 10-31-2012 03:54 PM
[SOLVED] Bash script to read line by line and execute commands Striketh Programming 4 11-06-2011 12:38 PM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 11:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:45 AM.

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