在“找不到命令”错误中,在“ bash”之前加破折号“-”是什么意思?

埃文·普赫塞

当您在bash提示符下输入无效命令时,您会收到消息

-bash: {command}: command not found

什么是-在开始的时候意味着什么?

约翰1024

这意味着它是一个登录shell。

来自man bash

登录外壳是一个参数为零的第一个字符为-的外壳程序,或以--login选项开头的外壳程序。

(在bash术语中,“ zeroth”自变量是命令名称,在您的情况下为bash。)bash以此为信号来执行登录活动(例如execute.bash_profile等)。

可以自动添加破折号的一种方法是,如果外壳以开头execBash手册

exec [-cl] [-a name] [command [arguments]]

[...]如果-l提供了选项,则shell在传递给command的第零个参数的开头放置一个破折号

例子

比较这两次尝试运行命令的尝试nonexistent首先没有-l

$ exec bash
$ nonexistent
bash: nonexistent: command not found

其次,具有:

$ exec -l bash
$ nonexistent
-bash: nonexistent: command not found

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章