ETiV
V2EX  ›  问与答

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

  •  
  •   ETiV · Sep 9, 2014 · 4490 views
    This topic created in 4297 days ago, the information mentioned may be changed or developed.
    从 .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 replies    2014-09-09 10:40:15 +08:00
    paulw54jrn
        1
    paulw54jrn  
       Sep 9, 2014   ❤️ 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  
       Sep 9, 2014
    @paulw54jrn Is it zsh only?
    pfitseng
        3
    pfitseng  
       Sep 9, 2014   ❤️ 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
       Sep 9, 2014
    @paulw54jrn
    @pfitseng

    懂了! thanks
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5528 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 52ms · UTC 07:45 · PVG 15:45 · LAX 00:45 · JFK 03:45
    ♥ Do have faith in what you're doing.