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

请教一个 shell 问题

  •  
  •   SmartDancer · 2017-04-25 22:03:41 +08:00 · 1174 次点击
    这是一个创建于 2529 天前的主题,其中的信息可能已经有所发展或是发生改变。
    为何当变量 var 为空时,命令 [ -e $var ] 状态码是 0 ?
    thanks
    SoloCompany
        1
    SoloCompany  
       2017-04-26 00:15:08 +08:00
    加引号

    http://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html#index-test

    The test and [ builtins evaluate conditional expressions using a set of rules based on the number of arguments.

    0 arguments
    The expression is false.

    1 argument
    The expression is true if and only if the argument is not null.
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    SmartDancer
        2
    SmartDancer  
    OP
       2017-04-26 08:09:53 +08:00 via Android
    @SoloCompany thank you! 请教一下这个问题如何 google 关键词!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2883 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 13:55 · PVG 21:55 · LAX 06:55 · JFK 09:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.