lib/pvl/cmd.sh
author Tero Marttila <terom@paivola.fi>
Mon, 02 Mar 2015 21:47:08 +0200
changeset 706 0816716c3f66
parent 627 a81206440be2
child 709 4e0450dc57a9
permissions -rw-r--r--
README: dhcp:subclass
### Command execution
## Execute command, possibly logging its execution.
#
#   cmd     $cmd...
#
# Fails if the command returns an error exit code.
function cmd {
    log_cmd "$@"

    "$@" || die "Failed: $@"
}

## Execute command as a test, logging its execution at log_cmd
#
#   cmd_test $cmd... && ... || ...
#
# Fails if the command returns an error exit code.
function cmd_test {
    log_cmd "$@"

    "$@"
}
## Execute command, prefixing its output on stdout with given indent prefix.
#
#   indent  "    " $cmd...
#
# Output is kept on stdout, exit status is that of the given command.
function cmd_indent () {
    local indent="$1"; shift

    "$@" | sed "s/^/$indent/"

    return ${PIPESTATUS[0]}
}