V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
ETiV
V2EX  ›  问与答

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

  •  
  •   ETiV · 2014-09-09 08:06:48 +08:00 · 4078 次点击
    这是一个创建于 3737 天前的主题,其中的信息可能已经有所发展或是发生改变。
    从 .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 不到
    4 条回复    2014-09-09 10:40:15 +08:00
    paulw54jrn
        1
    paulw54jrn  
       2014-09-09 08:15:55 +08:00   ❤️ 3
    搬运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
        2
    yangg  
       2014-09-09 09:16:12 +08:00
    @paulw54jrn Is it zsh only?
    pfitseng
        3
    pfitseng  
       2014-09-09 09:28:52 +08:00   ❤️ 3
    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
        4
    ETiV  
    OP
       2014-09-09 10:40:15 +08:00
    @paulw54jrn
    @pfitseng

    懂了! thanks
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3241 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 12:58 · PVG 20:58 · LAX 04:58 · JFK 07:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.