在某处我遇到了具有以下格式的终端命令:
command-name > &! file-name
Run Code Online (Sandbox Code Playgroud)
应该怎么做?
我所知道的唯一有效的 shell> &!是(t)csh. 来自man tcsh:
Run Code Online (Sandbox Code Playgroud)> 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
Run Code Online (Sandbox Code Playgroud)
然后
$ csh -c 'set noclobber; ls -l file nofile > & outfile'
outfile: File exists.
Run Code Online (Sandbox Code Playgroud)
但是添加 !
$ csh -c 'set noclobber; ls -l file nofile > &! outfile'
Run Code Online (Sandbox Code Playgroud)
成功。因此!与 中的含义有些相似vi。
| 归档时间: |
|
| 查看次数: |
101 次 |
| 最近记录: |