There was a need to convert 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 

Conclusion

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

How to multiply the output of the operation by the number?

    2 answers 2

    invalid arithmetic operator (error token is ".760000 * 1000")

    bash does not implement floating point arithmetic (only integer).

    for the implementation of such calculations will have to use some other program. for example, bc :

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

    or dc :

     result=$(echo "$a $b + p" | dc) 

    details:


    By the way, in this expression, dollar signs are not needed before variable names:

     result=$(($a*$b)) 

    enough (and more correctly) like this:

     result=$((a*b)) 

      The correct multiplication operation is performed like this.

       echo $[$a*$b] echo $[5*10] 

      If you need to multiply the whole by the real, then you need to execute the command

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

      scale - accuracy

      • you should still use $((a*b)) . After all: The old format $ [expression] is deprecated and will be removed in the upcoming versions of bash. - aleksandr barakin
      • With <pre> #! / Bin / bash a = $ code syntax error: invalid arithmetic operator (error token is ".760000 * 1000") which is also not true. - Evgeniy A
      • As I understand it, I don’t like the point in the number? - Evgeniy A