tcpping icon indicating copy to clipboard operation
tcpping copied to clipboard

Script fails when run with `dash`

Open dinwiggy opened this issue 5 years ago • 3 comments

$ tcpping -C -x 5 localhost 80
/usr/bin/tcpping: 341: [: auto: unexpected operator

Working fixes:

  • Changing line 341 to use = instead of ==.
  • Changing line 1 to use /bin/bash.

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

dinwiggy avatar Nov 28 '20 19:11 dinwiggy

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.

deajan avatar Apr 20 '21 14:04 deajan

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.

dinwiggy avatar Apr 20 '21 19:04 dinwiggy

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
$ 

az-blip avatar May 17 '21 10:05 az-blip

Retested against bash, dash and zsh.

deajan avatar Sep 04 '24 17:09 deajan