Skip to content

Conversation

@Mikachu2333
Copy link
Collaborator

问题描述

  1. fix 某些 Linux 系统不存在 which 来检查命令的存在 #257

方案与实现

换用 command -v,这玩意应该是都有的

@github-actions
Copy link

Hi @Mikachu2333,

❤️ 感谢你的贡献!你的 PR 当前基于 main 分支,请修改使用 dev 分支

@Mikachu2333 Mikachu2333 changed the base branch from main to dev August 19, 2025 07:25
@Mikachu2333
Copy link
Collaborator Author

command命令是 POSIX 标准的一部分,所以其理应可用。

command - run a program

command [OPTIONS] [COMMANDNAME [ARG ...]]

DESCRIPTION
command  forces  the shell to execute the program COMMANDNAME and ignore any functions or builtins with
the same name.

The following options are available:

-a or --all
       Prints all COMMAND found in PATH, in the order found.

-q or --query
       Silence output and print nothing, setting only exit status.  Implies --search.  For  compatibil‐
       ity, this is also --quiet (deprecated).

-v (or -s or --search)
       Prints the external command that would be executed, or prints nothing if no file with the speci‐
       fied name could be found in PATH.

-h or --help
       Displays help about using this command.

With the -v option, command treats every argument as a separate command to look up and  sets  the  exit
status  to 0 if any of the specified commands were found, or 127 if no commands could be found. --quiet
used with -v prevents commands being printed, like type -q.

EXAMPLES
command ls executes the ls program, even if an ls function also exists.
command -s ls prints the path to the ls program.
command -q git; and command git log runs git log only if git exists.

@combinx
Copy link

combinx commented Aug 19, 2025

图片

@combinx
Copy link

combinx commented Aug 19, 2025

图片

@combinx
Copy link

combinx commented Aug 19, 2025

在 debian 和 manjaro 均不是理想输出

@Mikachu2333
Copy link
Collaborator Author

在 debian 和 manjaro 均不是理想输出

恰恰相反,是理想输出,你后面不跟东西就是啥都没有啊,就好像你单独运行了 while 一样,用法是 command -v <你想查找的程序>,例如 command -v chsrc

@combinx
Copy link

combinx commented Aug 19, 2025

我以为 -v 是 --version 的缩写,是我没认真了

@ccmywish ccmywish added this to the v0.2.3 milestone Aug 19, 2025
@ccmywish ccmywish added the Linux Linux相关 label Aug 19, 2025
Copy link
Contributor

@ccmywish ccmywish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个方案很好 👍👍👍

把注释调整一下就行了

@ccmywish ccmywish merged commit b6a9101 into RubyMetric:dev Aug 20, 2025
@Mikachu2333 Mikachu2333 deleted the fix/which_no_exist branch August 20, 2025 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Linux Linux相关

Projects

None yet

Development

Successfully merging this pull request may close these issues.

某些 Linux 系统不存在 which 来检查命令的存在

3 participants