#!/bin/bash tmpfile=$(mktemp /tmp/cmd-output.XXXXXX) trap 'rm "$tmpfile"' 0 1 15 echo "\$ $@" | tee $tmpfile eval "$@" |& tee -a $tmpfile cat $tmpfile | xclip -sel c