暗能星系

    • 登录
    • 搜索

    ls -0 > /dev/null 2>&1

    小技巧
    1
    1
    6
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • A
      anneng 最后由 编辑

      suppressing the error output (stderr) of the ls -0 command, redirect it to standard output (stdout), writing it to /dev/null thereby immediately discarding it.

      This technique is commonly used to tell whether a command exists, which you can use for handling different operating systems, automatically installing packages, downloading files, and most importantly defending your scripts and systems from unexpected exceptions.

      function cmd_exists() {
      command -v $1 > /dev/null 2>&1
      }

      cmd_exists ls; echo $?

      cmd_exists sl; echo $?

      1 条回复 最后回复 回复 引用 0
      • First post
        Last post
      Powered by 暗能星系