lib/pvl/cmd.sh
changeset 627 a81206440be2
child 709 4e0450dc57a9
equal deleted inserted replaced
626:5cd99761fe4d 627:a81206440be2
       
     1 ### Command execution
       
     2 ## Execute command, possibly logging its execution.
       
     3 #
       
     4 #   cmd     $cmd...
       
     5 #
       
     6 # Fails if the command returns an error exit code.
       
     7 function cmd {
       
     8     log_cmd "$@"
       
     9 
       
    10     "$@" || die "Failed: $@"
       
    11 }
       
    12 
       
    13 ## Execute command as a test, logging its execution at log_cmd
       
    14 #
       
    15 #   cmd_test $cmd... && ... || ...
       
    16 #
       
    17 # Fails if the command returns an error exit code.
       
    18 function cmd_test {
       
    19     log_cmd "$@"
       
    20 
       
    21     "$@"
       
    22 }
       
    23 ## Execute command, prefixing its output on stdout with given indent prefix.
       
    24 #
       
    25 #   indent  "    " $cmd...
       
    26 #
       
    27 # Output is kept on stdout, exit status is that of the given command.
       
    28 function cmd_indent () {
       
    29     local indent="$1"; shift
       
    30 
       
    31     "$@" | sed "s/^/$indent/"
       
    32 
       
    33     return ${PIPESTATUS[0]}
       
    34 }