while read line

Hi,

I have this type of bash code:

#!/bin/bash
while read -r line; do
  echo $line | /usr/local/example/program.sh
done

My question is, why if I put an echo statement inside the while loop it does not execute such as this:

while read -r line; do
 echo $line > file #this doesn't work
  /bin/echo $line | /usr/local/example/program.sh #this works
done

Yet, program.sh does process the $line.

For the record I am executing the script like this in shell terminal:

echo "statement" | /usr/local/programs/input.sh 

What black magic is this?

Hi,
I have tried your code and its work fine for me.Please post the program.sh and error if you are recieving

while read -r line; do
 echo $line > file #this  work for me
  ##/bin/echo $line | /usr/local/example/program.sh #this works
done

program.sh is working for me.
Anything else doesn't, no errors. I have tried this exhaustively. I think I'll just give up cause its driving me nuts.

The actual scripts I wrote are much longer. It didn't work for them, and when I narrowed it down this was the main problem.

---------- Post updated at 09:21 AM ---------- Previous update was at 08:34 AM ----------

Okay, so my fault here I over simplified my example in OP.

This is more of what I'm doing which for the line previous to the send_nsca binary program is not working:

in shell:

echo "host,log,0,message" | program_below.sh

program:

while read -r line; do
  STRING=$line
        echo $STRING > /usr/local/nagios/syslog/debug #and I see no output in debug file
        echo $STRING | /usr/local/nagios/libexec/send_nsca -H 192.168.93.55 -d ',' -c /usr/local/nagios/etc/send_nsca.cfg #this works
done

HELP!!! LOL :confused:

---------- Post updated at 10:27 AM ---------- Previous update was at 09:21 AM ----------

These are all working, my bad, but for some reason they didn't before.

Solved the problem.

I am using syslog-ng program() as a destination for a log.

Apparently, the problem has to do with the absolute path in the script. I'm guessing if calling with program() it leaves the directory that script is called from, so the absolute path is necessary. Either way, it works now to:
absolute_path/debug.log

Thanks for the response, hours upon hours again wasted for nothing, I will ALWAYS freaken add an absolute path to every line of every script from now on. Lesson learned.