Output of until to file versus stdout

Why does this

until false; do history | head -5; done

result in a stdout infinite loop, yet

until false; do history | head -5 > hist5; done

only writes it once to file hist5 ? Furthermore, I can hear the hard drive working on the 2nd command until I end the process, but the history | head -5 is only written once.

It does not write once. It writes continously without break the same 5 lines into hist5 file over and over and generates considerable load at your machine. Since every session has its own history this makes no sense to do.

I'm unsure, but I assume .bash_history file is written at logout. If you want to see another sessions history with this, this will not work.

1 Like