Linux 输出重定向符号 `>!` 是啥意思?

2014-09-09 08:06:48 +08:00
 ETiV
从 .oh-my-zsh/tools/check_for_upgrade.sh 看到的:

https://github.com/robbyrussell/oh-my-zsh/blob/master/tools/check_for_upgrade.sh#L8

```
echo "LAST_EPOCH=$(_current_epoch)" >! ~/.zsh-update
```

单独的>, 两个>> 都见过. >! 第一次见. Google 不到
4069 次点击
所在节点    问与答
4 条回复
paulw54jrn
2014-09-09 08:15:55 +08:00
搬运http://zsh.sourceforge.net/Doc/Release/Redirection.html

>| word
>! word
Same as >, except that the file is truncated to zero length if it exists, even if CLOBBER is unset.
yangg
2014-09-09 09:16:12 +08:00
@paulw54jrn Is it zsh only?
pfitseng
2014-09-09 09:28:52 +08:00
http://en.wikipedia.org/wiki/Clobbering

$ echo "Hello, world" >file.txt
$ echo "This will overwrite the first greeting." >file.txt
$ set -o noclobber
$ echo "Can we overwrite it again?" >file.txt
-bash: file.txt: cannot overwrite existing file
$ echo "But we can use the >| operator to ignore the noclobber." >|file.txt
$ # Successfully overwrote the contents of file.txt using the >| operator
$ set +o noclobber # Changes setting back
ETiV
2014-09-09 10:40:15 +08:00
@paulw54jrn
@pfitseng

懂了! thanks

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/132387

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX