I'm testing the portability of some stuff I'm writing to BSD. It's working on Linux, FreeBSD, OpenBSD. It isn't working on NetBSD.
The following is on a fresh VM installation I've made just for the purpose of testing this. I've traced the issue to
NetBSD$ uname -a
NetBSD NetBSD.local 9.1 NetBSD 9.1 (GENERIC) #0: Sun Oct 18 19:24:30 UTC 2020 mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64
NetBSD$ cat /etc/shells
# $NetBSD: shells,v 1.3 1996/12/29 03:23:07 mrg Exp $
#
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.
/bin/sh
/bin/csh
/bin/ksh
/usr/pkg/bin/zsh
/usr/pkg/bin/bash
NetBSD$ for s in /bin/sh /bin/csh /bin/ksh /usr/pkg/bin/zsh /usr/pkg/bin/bash ; do echo $s; $s -c "echo OK" ; done
/bin/sh
/bin/csh
OK
/bin/ksh
/usr/pkg/bin/zsh
OK
/usr/pkg/bin/bash
OK
NetBSD$ su -
Password:
NetBSD# for s in /bin/sh /bin/csh /bin/ksh /usr/pkg/bin/zsh /usr/pkg/bin/bash ; do echo $s; $s -c "echo OK" ; done
/bin/sh
OK
/bin/csh
OK
/bin/ksh
OK
/usr/pkg/bin/zsh
OK
/usr/pkg/bin/bash
OK
Why doesn't sh -c "echo OK"
and ksh -c "echo OK"
work when I'm a non-root user, and why do they work when I'm root?
Other shells (csh
, zsh
, bash
) work correctly, as shown above.
sh -c "echo OK"
not print anything if you give that command by itself, or is it only when it's part of your loop? – Kusalananda♦ Nov 22 '20 at 16:46SHA1 (/bin/sh) = f3d8c4ba3aec3baefa2e5758e628694afc190b85
andSHA1 (/bin/ksh) = b0835284c64fefceac9d96b34e8a482473716ec5
? (use thesha1
command on the shell executables). – Kusalananda♦ Nov 22 '20 at 17:08