I'm iterating through an array of integers ${startTimes}
(marker locations in an audio file, in samples) and using bc
to convert those integers to milliseconds. I'm passing the results into a new array ${msValuesArray}
. If I run each array element one at a time it works fine. If I run it in a for
loop:
for i in $(seq 0 ${#startTimes[@]}); do
msValuesArray+=($(bc <<< ${startTimes[i]}/44.1))
done
The resulting ${msValuesArray}
contains the expected results, but the terminal outputs (standard_in) 1: parse error
.
While I intend to use this in a shell script, and after reading other questions here I learned that adding #!/bin/bash
to the beginning of the command avoids the parse error, I still don't understand the following:
a) why does the manual passing of a ${startTimes}
element into bc
work without the parse error while the for
loop also works, yet outputs the parse error (outside of the shell script)?
b) despite the parse error, I have the resulting array that I want. Should I ignore the error?
c) when adding #!/bin/bash
to the beginning of the commands (still outside of the shell script, just in the command line) why are the results inaccessible? (Entering echo ${msValuesArray[@]}
returns an empty array.)
d) While running inside the shell script, is the same error happening but just not printing to the terminal?
Any help is appreciated. Thanks.