Reasons to use cat unnecessarily

Recently, I read on planet debian another rant along the lines of “why oh why do people use cat when they could just redirect from a file?” – but not that this is a new complaint from expert users.

I’ve got one big reason for using cat on the command-line: it’s far too easy to type gpg >encryptedfile when you mean gpg <encryptedfile and almost no systems have noclobber switched on by default any more, even on shells that support such an option. So you end up losing a valuable data file and having to recover it from backups – I’ve seen it happen too often.

Because the pipe symbol is nowhere near anything destructive, cat encryptedfile |gpg seems far less likely to end in tears, so I try not to criticise someone for doing that.

That doesn’t completely excuse using it in a script file, though, especially if it’s used lots.

Is there another way I’ve forgotten that would reduce the risk of a destructive typo in the redirection?

This entry was posted in GNU/Linux and tagged , , , , , , , , . Bookmark the permalink.