How to convert BASH script to DASH or other solutions?

Solution 1:

There are two different function syntaxes in bash/ksh/zsh. You're using the ksh style: function name { … }. The other form is just name() { … } and is the form introduced late in the original Bourne shell.

It really is pointless to do:

    if cmd; then
      true
    else
      false
    fi

Apart from turning all non-zero return statuses to 1, this is just the same as just running cmd. And with the function reduced to just one line, you really don't need a function. I'd also be tempted to use cmp -s instead of diff or to simply do the copy unconditionally. And don't use ls to test for the existence of a file. Either the test command or the [ is intended for that purpose: [ -e /etc/rsyslog.d/xdr.conf ]. That does exist in external form if you have sudo.