screencast icon indicating copy to clipboard operation
screencast copied to clipboard

dash shell chokes on quoted variables in arithmetic expressions

Open jlinkels opened this issue 2 years ago • 0 comments

When using dash to run screencast it terminated with this error message:

dash /usr/local/bin/screencast -s 1280x720 -p 200,234 sc2.mp4
screencast v1.6.0 - Copyright (c) 2015-2023 Daniel Bermond
Command line interface to record a X11 desktop
https://github.com/dbermond/screencast/
[ screencast ] initializing
/usr/local/bin/screencast: 3215: arithmetic expression: expecting primary: ""1280" % 8"

The error is caused by this code (line 66 in screen.sh)

check_dimension() {
    # the dimension will be a multiple of 8 if the remainder is 0
    [ "$(("$1" % 8))" = '0' ]
}

The cause is that "$1" is quoted. When removing the quotes, dash processes this fine. [ "$(("$1" % 8))" = '0' ]

I would say that quotes are not needed. If the value of parameter is empty or contains spaces the result should be invalid anyway.

Debian uses /bin/sh as a symbolic link to dash. So when calling screencast as executable it terminates with this error. The easiest solution for Debian users is to call screencast explicitely with bash.

Or, as I did, replace the symbolic link with a pointer to bash. I cannot imagine when I would use dash instead.

jlinkels

jlinkels avatar Jan 03 '23 13:01 jlinkels