deajan / tcpping

tcpping script for smokeping that runs with newer linux traceroute binaries
GNU General Public License v3.0
127 stars 39 forks source link

Script fails when run with `dash` #11

Closed dinwiggy closed 1 month ago

dinwiggy commented 3 years ago
$ tcpping -C -x 5 localhost 80
/usr/bin/tcpping: 341: [: auto: unexpected operator

Working fixes:

checkbashisms reports possible issues on lines 75, 160, 165, 341.

deajan commented 3 years ago

What OS did you run this on ? Changing line 1 to /usr/bin/env bash could possibly make tcpping fail on FreeBSD, need to investigate.

dinwiggy commented 3 years ago

I honestly don't remember. I would guess smokeping on a recent version of either raspbian or ubuntu. The only problem was the use of == on line 341. Dash is apparently the worst but not only offender: https://unix.stackexchange.com/a/382012

Bash isn't providing any features here, so there's not a need to use it, and like you said there's potential issues with forcing it. I only gave that as one of the ways I resolved it to be thorough. For cross-shell compatibility, avoiding bashisms seems preferable anyway.

az-blip commented 3 years ago

Hi, Same behavior on ubuntu 20.10. == is not a valid operator on this dash version.

alice@bob:~/src$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.10
Release:    20.10
Codename:   groovy
alice@bob:~/src$ which sh
/usr/bin/sh
alice@bob:~/src$ ls -l /usr/bin/sh
lrwxrwxrwx 1 root root 4 mars  30  2020 /usr/bin/sh -> dash
alice@bob:~/src$ apt-cache policy dash
dash:
  Installed: 0.5.10.2-7
  Candidate: 0.5.10.2-7
  Version table:
 *** 0.5.10.2-7 500
        500 http://fr.archive.ubuntu.com/ubuntu groovy/main amd64 Packages
        100 /var/lib/dpkg/status
alice@bob:~/src$ dash
$ test "a" == "b"
dash: 1: test: a: unexpected operator
$ test "a" = "b"
$ echo $?
1
$ 
deajan commented 1 month ago

Retested against bash, dash and zsh.