我在某处遇到了具有以下格式的终端命令:
command-name > &! file-name
该怎么办呢?
答案1
据我所知唯一> &!
有效的 shell 是(t)csh
。来自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.
例如,如果file
存在但nofile
不存在,则
$ 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
然后
$ csh -c 'set noclobber; ls -l file nofile > & outfile'
outfile: File exists.
但添加!
$ csh -c 'set noclobber; ls -l file nofile > &! outfile'
成功。因此 的!
含义与 中 的含义有些相似vi
。