Hi,
I have a really strange problem that's giving me some major headaches and wondered if the bright minds of linuxquestions might be able to help me out.
This problem is two fold really... I shall explain...
I've got a script in which I need to pass variables from within a loop back to the main script. Using pipes in a loop in bash apparently spawns a subshell and as such the variable values are lost once the loop exits.
So, I had something like this...
Code:
cat file.txt | while read line
do
something
retval=$?
done
echo ${retval}
This didn't work because of the pipe / subshell thing...so I changed it to this...
Code:
while read line
do
something
retval=$?
done < <(cat file.txt)
echo ${retval}
Now this worked fine while I was testing it using the default bash shell on a RedHat EL 4 box.
However, the script is to be used in an automation product (BladeLogic), and when that executes the script it uses /bin/sh to do it instead of /bin/bash and it fails with a message like unexpected < near token ( or some such, basically a syntax error.
Now the really weird thing is, that when I tested the script manually again, still on the same server, I found that if executed it like this...
...it worked. But if I did this...
...it failed with the syntax error.
But now the really strange part. If on the same server I do which sh it tells me /bin/sh, and if I do ls -l /bin/sh it shows me it that /bin/sh is just a symbolic link to /bin/bash!
And I am completely stumped by this :-(
Thanks - Lee