找不到expr命令?为什么找不到expr,但其他所有东西都没有? [英] expr command not found? Why is expr not found but everything else is?

查看:50
本文介绍了找不到expr命令?为什么找不到expr,但其他所有东西都没有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了几个小时试图使下面的代码正常工作

I have spent several hours trying to make the following piece of code work

    PATH="C:\Ben\MyPictures"
    echo $PATH
    MY=`expr 2 + 2`

,但这将不起作用,因为"expr:命令未找到".我在StackOverflow上挖到的唯一东西是路径问题(即设置我的环境变量),但是如果那是问题,为什么其他函数(例如echo,let和声明)已经可以正常工作了?

but this will not work because "expr: command not found". The only thing I've dug on StackOverflow are pathing issue (I.E. set my environment variable), but if that's the problem, why would other functions like echo, let, and declare already work fine?

有关更多信息,这是在window的cygwin的近乎全新的安装中.我的问题是为什么我找不到expr?

For more context, this is on a near-fresh installation of window's cygwin. My question is why can't I find expr?

推荐答案

您已将 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)

这篇关于找不到expr命令?为什么找不到expr,但其他所有东西都没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆