lib/pvl/cmd.sh
author Tero Marttila <tero.marttila@aalto.fi>
Mon, 02 Mar 2015 13:26:34 +0200
changeset 687 f99f9e3d02cf
parent 627 a81206440be2
child 709 4e0450dc57a9
permissions -rw-r--r--
pvl.hosts.zone: make non-CNAME check_conflicts optional
### 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]}
}