Evgeniy A Evgeniy A - 3 months ago 12
Linux Question

Multiply by the number of command output

Good afternoon there was a need to translate seconds to milliseconds. Script:

#!/bin/bash
a=$(ffprobe -i c848a39afc54e04cc64ddd955686654b9b1c6f31 -show_entries format=duration -v quiet -of csv="p=0");
b=1000;
result=$(($a*$b));
echo $result


output

./sectomilisec: line 4: 23.760000*1000: syntax error: invalid arithmetic operator (error token is ".760000*1000")

Answer

bash doesn't support float operation. You can use bc for this:

result=$(echo "$a*$b" | bc)