Oddbean new post about | logout
 Bash - a small function which can both display output and log the actions of most any command (avoid sed due to it's nature):

    # run action, log output, return exit code
    # - passing in 'sed' should be avoided
    # - functions can only return 0..254
    # -- set a global to check as needed
    ACTLOG="/tmp/action.log"
    _ACTRET=0
    function logact() {
      local ACTION
      ACTION="$*"
      ${ACTION} 2>&1 | tee -a "${ACTLOG}"
      _ACTRET=${PIPESTATUS[0]}
      return ${_ACTRET}
    }

Usage examples:

    logact mkinitcpio -p linux
    logact pacman -Syu --noconfirm --noprogressbar
    logact systemctl enable sshd.service

#bash #linux #opensource