Somewhere I encountered a Terminal command that has the following format:
command-name > &! file-name
What is supposed to do?
The only shell that I know of in which > &!
is valid is (t)csh
. From man tcsh
:
> name >! name >& name >&! name The file name is used as standard output. If the file does not exist then it is created; if the file exists, it is trun‐ cated, its previous contents being lost. If the shell variable noclobber is set, then the file must not exist or be a character special file (e.g., a terminal or `/dev/null') or an error results. This helps prevent acciden‐ tal destruction of files. In this case the `!' forms can be used to suppress this check. If notempty is given in noclob‐ ber, `>' is allowed on empty files; if ask is set, an interacive confirmation is presented, rather than an error. The forms involving `&' route the diagnostic output into the specified file as well as the standard output. name is expanded in the same way as `<' input filenames are.
Ex. if file
exists but nofile
doesn't, then
$ csh -c 'set noclobber; ls -l file nofile > & outfile'
$ cat outfile
ls: cannot access 'nofile': No such file or directory
-rw-r--r-- 1 steeldriver steeldriver 70 Nov 22 15:10 file
Then
$ csh -c 'set noclobber; ls -l file nofile > & outfile'
outfile: File exists.
But adding !
$ csh -c 'set noclobber; ls -l file nofile > &! outfile'
succeeds. So the !
has a somewhat similar meaning to that in vi
.
&
) has different meanings in different contexts. For instance, this article (bashitout.com/2013/05/18/Ampersands-on-the-command-line.html) explains that apersand at the end of a command causes to run it in the backround.
Nov 24, 2019 at 13:06