且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

找不到expr命令?为什么找不到expr,但其他所有东西都没有?

更新时间:2023-11-18 14:14:25

您已将 PATH 修改为仅具有1个目录(因此无法找到 expr ).您必须将新路径附加到 PATH 上,而不要替换现有的 PATH 值,例如:

You have modified your PATH to have only 1 directory(therefore it cant find expr). You must append your new path to PATH and not replace existing PATH values, like this:

export PATH="$PATH:C:\Ben\MyPictures"

还可以使用bash的内置算术评估来代替调用外部进程 expr 进行计算:

Also instead of calling an external process expr for calculation you can use the bash's builtin arithmetic evaluation:

$ echo $((2+2))
4

是的,因为它们不是在 $ PATH 中列出的目录中找到的不是可执行文件,所以它们能起作用.

Yes those would work because they are not executable files found from directories listed in $PATH.

相反,它们( echo type 等)是由 bash shell本身提供的功能,称为shell内置程序.

Instead they(echo, type etc) are functionality provided by the bash shell itself called shell built-ins.

输入 type echo type expr 知道它是哪种命令(别名/shell内置/可执行文件等)

Type out type echo and type expr to know what type of command is it(alias/shell builtin/executable file etc.)

Shell内置帮助通常可以在 help shellBuiltin 中找到,在该示例中,我们使用 man 页作为可执行文件.

Shell built-ins help can be usually found out by help shellBuiltin where as we use man pages for executable files.

PS: type 本身是内置的shell(请参见 type type )

PS: type itself is a shell built-in(see type type)