csfpost.sh doesn't use shebang

Post Reply
getup
Junior Member
Posts: 7
Joined: 27 Dec 2013, 19:38

csfpost.sh doesn't use shebang

Post 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)
brianoz
Junior Member
Posts: 34
Joined: 10 Dec 2006, 21:15

Re: csfpost.sh doesn't use shebang

Post by brianoz »

getup wrote: 26 Jan 2018, 08:47

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
Post Reply