ROB ENGG
ROB ENGG

Reputation: 67

shell while read command execution

Please help me to find out this problem solution

 #!bin/bash 
 while read line; do

  if [[ $line =~ "some thing match on line"]] ; then
    echo  "---->   $line"
    NAME=$(echo "$line" | awk '{print $2}' | cut -d"=" -f2)
    PATH=$(echo "$line" | awk '{print $3}' | cut -d"=" -f2)  
  fi
done < "pattern.xml"
#output
##line 6: awk: command not found
##line 6: cut: command not found

why this command not execute inside while loop
Thanks in advance

Upvotes: 0

Views: 39

Answers (1)

Barmar
Barmar

Reputation: 780974

You're setting the PATH environment variable here:

PATH=$(echo "$line" | awk '{print $3}' | cut -d"=" -f2) 

That variable is the search path used to find programs. So after the first iteration of the loop, you won't be able to find programs, because it no longer contains directories like /usr/bin.

Use a different variable name. And in general, avoid using all uppercase variables in your scripts, as this is conventionally reserved for environment variables.

Upvotes: 1

Related Questions