Your problem is a missing newline (or, in extremis, semicolon). Your script is:
for file in baselines/*; do numThreads=$(echo $file | gawk 'BEGIN { FS = "." } ; {print $3 }') echo "Number of Threads: $numThreads" >> $file; done
You need a newline or semicolon before the echo "Number of Threads..."
part. Like this for readability:
for file in baselines/*
do
numThreads=$(echo $file | gawk 'BEGIN { FS = "." } ; {print $3 }')
echo "Number of Threads: $numThreads" >> $file
done
Like this if you insist on writing unreadable code:
for file in baselines/*; do numThreads=$(echo $file | gawk 'BEGIN { FS = "." } ; {print $3 }'); echo "Number of Threads: $numThreads" >> $file; done
but please don't send code like that to Stack Overflow for review/revision again because it is hard to read and people won't bother to answer questions where it is hard to read the code.
Incidentally, what your code did is quite subtly wrong. It ran the echo
command with the environment variable numThreads
set to the correct value, but the expansion of the argument list occurred before that so that numThreads
was empty as the "Number of Threads: $numThreads"
string was evaluated. One way to demonstrate that is:
for file in baselines/*
do
numThreads=$(echo $file | gawk 'BEGIN { FS = "." } ; {print $3 }') env | grep numThreads
done
which will print the value of the environment variable. Another way to demonstrate it would be:
for file in baselines/*
do
numThreads=$(echo $file | gawk 'BEGIN { FS = "." } ; {print $3 }') sh -c 'echo numThreads=$numThreads'
done