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.
startsarray look like? Does it have the same number of elements asstartTimes? Is this your whole script? How do you run it? What do you mean by "adding#!/bin/bashin the command line"?startTimes. I don't have the whole script yet, just testing out commands one at a time in the command line to make sure my script will run (if there's a better method I'm all ears). For the shebang, if I enter all of this#!/bin/bash; for...(etc)...; donein the command line I get no parse error -- but also no accessible results. I'm assuming it's running in another shell that I can't access? Still learning, obviously.startTimeslooks like this:0 87053 91463 190062 194472 290520 294930 387582 391992. Just a bunch of integers.