Page 1 of 1

csfpost.sh doesn't use shebang

Posted: 26 Jan 2018, 08:47
by getup
It seems that csf runs csfpost.sh with sh instead of just using the shebang that was specified. This causes some unexpected behaviour if you need more logic in these files.

I can only reproduce this on Ubuntu, CentOS has no problems. I've added the following code to csfpost.sh:
Code: Select all
#!/bin/bash
if [ ! "$BASH_VERSION" ] ; then
    echo "Please do not use sh to run this script ($0)"
fi
Code: Select all
Running /etc/csf/csfpost.sh
Please do not use sh to run this script (/etc/csf/csfpost.sh)

Re: csfpost.sh doesn't use shebang

Posted: 19 Apr 2018, 07:46
by brianoz
26 Jan 2018, 08:47getup wrote:
Code: Select all
#!/bin/bash
if [ ! "$BASH_VERSION" ] ; then
    echo "Please do not use sh to run this script ($0)"
fi
I'd suspect this is because /bin/sh is actually bash (or bash family) on one but not the other - check out /bin/sh and /usr/sbin/sh. A simple solution is to exec bash if you really need the logic, or to rewrite so it works in pure sh (generally possible, but not always easily) - code would look something like this (untested):
Code: Select all
#!/bin/bash
if [ ! "$BASH_VERSION" ] ; then
    echo "Please do not use sh to run this script ($0)"
    exec /bin/bash $0 "$@"
fi