1

Somewhere I encountered a Terminal command that has the following format:

command-name > &! file-name

What is supposed to do?

1
  • 1
    this is very vague what is the exact command? Nov 23, 2019 at 16:25

1 Answer 1

5

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.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .