On 3/18/21 1:32 PM, Scott Andrews wrote:

Although the init-functions and rc scripts currently run properly, what
you propose below is a bit cleaner.

I'll note that the scripts were initially written to be posix compatible (no bashisms) and changing that is a different discussion. That's not correctly implemented in the rc, console, ifup, and ifdown scripts because of the use of == for comparisons.

example follows.........

remove SCRIPT_STAT from init-functions

Correctly write check_script_status in rc

function check_script_status {

'function' is not posix compatible.  It's not in any current script.

        local script=${1}
        SCRIPT_STAT="0"
        if [ ! -f ${script} ]; then
                log_warning_msg "${script} is not a valid file."
                SCRIPT_STAT=retval="1"

The = sign in scripts is overloaded. Is it a comparison or an assignment? I've never seen the above in a script before, although it is used in C/C++. We should not use it in a script.

        fi
        if [ ! -x ${script} ]; then
                log_warning "${script} is not executable."
                SCRIPT_STAT=retval="1"

as above

        fi
        return
}

#       Check script for file and executable
check_script_status
if [ "1" = ${SCRIPT_STAT} ]; then continue; fi

That fixes the issue but I would rewrite check_script_status to
return true or false then then do this

function check_script_status {

as above

        local script=${1}
        local retval="0"
        if [ ! -f ${script} ]; then
                log_warning_msg "${script} is not a valid file."
                retval="1"
        fi
        if [ ! -x ${script} ]; then
                log_warning "${script} is not executable."
                retval="1"
        fi
        [ "0" = ${retval} ] && return 0 || return 1
}

if [ check_script_status ]; then continue; fi

or simply

[ check_script_status ] || continue

I prefer the more specific:

[ check_script_status = 0 ] || continue

From a style standpoint, there should always be an explicit test when using [ ].

  -- Bruce

--
http://lists.linuxfromscratch.org/listinfo/lfs-support
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page

Do not top post on this list.

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

http://en.wikipedia.org/wiki/Posting_style

Reply via email to