See solution at end of post.
I'm running into a frustrating problem. Thanks for any help you can give. What I'm trying to do is get all occurrences of certain values in an error file. I'm using process substitution to parse error output files. I created a test script with the following code and it works perfectly.
#--------------------
# Get all values of affiliate
echo "Building array of affiliates with errors"
while read -r line; do
AffiliateName_array+=($line)
i=$(( ${#AffiliateName_array[@]} - 1 ))
echo " ScriptName_array | index --> $i | $line"
done < <(grep Running ${LogDir}/temp_python_errors.txt | cut -d' ' -f5 | tr '[:lower:]' '[:upper:]')
The echo output looks like this:
Building array of affiliates with errors
index --> 0 | affiliate1
index --> 1 | affiliate2
Then I cut and pasted that exact code into the final script and it throws the error:
path/AR_exit_process.sh: line 166: syntax error near unexpected token `<'
path/Affiliate_Remits/AR_exit_process.sh: line 166: ` done < <(grep Running ${LogDir}/temp_python_errors.txt | cut -d' ' -f5 | tr '[:lower:]' '[:upper:]')'
Here's the code from my final script (exactly the same as the test script since it was cut and pasted):
#--------------------
# Get all values of affiliate
echo "Building array of affiliates with errors"
while read -r line; do
AffiliateName_array+=($line)
i=$(( ${#AffiliateName_array[@]} - 1 ))
echo " ScriptName_array | index --> $i | $line"
done < <(grep Running ${LogDir}/temp_python_errors.txt | cut -d' ' -f5 | tr '[:lower:]' '[:upper:]')
NOTES:
All scripts have the #!/bin/bash
bang line
The scripts run on the same server
The test script is called directly from the command line but
the final script is 2 layers deep. All calling scripts use #!/bin/bash
My main reference: https://wiki.bash-hackers.org/syntax/expansion/proc_subst
SOLUTION: As Charles suggested I added a line to both the test and final scripts with the command: set -o
I found that when running the test script, I got the value posix off
. However, when I ran the final script with set -o
I got posix on
. What this means is that the test script was running under bash while the final script was running under sh. The solution is to add the line set +o posix
to turn posix off before executing the code. What I'm still not clear about is how the posix setting is different on the same server. More research ...