I’m trying to get the mean volume of a recording and the echo the expected value. When I do it line by line, everything works fine, but as soon as I execute it in a bash script, I have a problem with the FFMPEG line. I identified the problem, which is that &> analysis
is not doing anything for some reason and instead of saving the output in a file it prints it in the shell.
I don’t know how to fix it since it works fine when not in a script.
#!/bin/bash
# Record sound
sh aud2.sh
# Run ff.sh in the background to analyze volume and save results
ffmpeg -i test.wav -af "volumedetect" -vn -sn -dn -f null - &> analysis.vol
# Extract mean_volume and save to mean.vol
grep "mean_volume" analysis.vol > mean.vol
# Extract numerical value and save to val.vol
sed -n 's/^.*mean_volume: ([-0-9.]*) dB.*/1/p' < mean.vol > val.vol
# Read the value from val.vol into the variable volume
volume=$(<val.vol)
echo "$volume"
Expected output when line by line
Actual output in bash script
I expected the shell output to be saved in a file.
1