“Clobbering” a file has a very specific meaning in Bash — it’s when you use the > redirect operator to overwrite an existing regular file. Setting noclobber results in a non–zero exit code when a script tries to clobber a file, leaving the file untouched. See for example this script, intended to get 32 bytes of random binary data and convert it to hexadecimal so that it can be stored in a configuration file:

noclobber also applies to symbolic links to regular files. Some special files like /dev/null are not actually changed when you attempt to clobber them. noclobber is smart enough to allow such redirects.


This page is a preview of The newline Guide to Bash Scripting

Start a new discussion. All notification go to the author.