Consider the following bash constructs:ls /usr/include/asm > list-redir.txtls /usr/include/asm | tee list-tee.txtIn this case, list-redir.txt and list-tee.txt will be identical, and will contain the listing of files as expected; e.g.$ head -5 list-redir.txta.out.hauxvec.hbitsperlong.hboot.hbootparam.h [...]My question is - how could I write such a command, and have the command line text inserted as the first thing in the standard output - such that the file eventually starts with the command line as first? As an example, the file list-redir.txt would in that case look like:$ head -5 list-redir.txt# ls /usr/include/asma.out.hauxvec.hbitsperlong.hboot.h [...]... which also implies that the character # can be prepended to the inserted command line.Is there anything that I could use for this - but with the minimum of change in typing out in respect to the original command lines (ls /usr/include/asm > list-redir.txt ...)?
Inserting the command line text before output in stdout (for pipe / redirection)
bash;io redirection;stdout
A simple (and ugly) hack would be to add this to your ~/.bashrc:echorun(){    echo # $@;    $@}You'd then run your command as echorun ls /usr > list-redir.txtThat will not let you differentiate between ls /usr >foo and ls /usr | tee foo but it will append # ls /usr to the beginning of foo.