Bash“未找到命令"错误 [英] Bash "command not found" error

查看:113
本文介绍了Bash“未找到命令"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用自定义功能编辑.bashrc文件以启动xwin.我希望它能够在多个窗口中打开,因此我决定创建一个接受1个参数的函数:显示编号.这是我的代码:

I am trying to edit my .bashrc file with a custom function to launch xwin. I want it to be able to open in multiple windows, so I decided to make a function that accepts 1 parameter: the display number. Here is my code:

function test(){
    a=$(($1-0))
    "xinit -- :$a -multiwindow -clipboard &"
}

之所以创建变量"a"来保存输入,是因为我怀疑输入是作为字符串而不是数字读入的.我希望采取将输入减去0的步骤会将字符串转换为整数,但是我实际上不确定是否会这样做.现在,当我打电话

The reason why I created a variable "a" to hold the input is because I suspected that the input was being read in as a string and not a number. I was hoping that taking the step where I subtract the input by 0 would convert the string into an integer, but I'm not actually sure if it will or not. Now, when I call

test 0

我得到了错误

-bash: xinit -- :0 -multiwindow -clipboard &: command not found

我该如何解决?谢谢!

推荐答案

之所以会发生这种情况,是因为bash将引号内的所有内容都解释为字符串.命令是一个字符串数组,其中的第一个元素是二进制文件或内部Shell命令.数组中的后续字符串将作为参数.

That happens because bash interprets everything inside quotes as a String. A command is an array of strings which the first element is a binary file or a internal shell command. Subsequent strings in the array are taken as argument.

键入时:

"xinit -- :$a -multiwindow -clipboard &"

shell认为您编写的所有内容都是命令.根据命令/程序,您运行的所有其他参数可以是单个字符串.但是大多数情况下,仅当您传递的参数内部带有空格时才使用引号:

the shell thinks that everything you wrote is a command. Depending on the command/program you ran all the rest of the arguments can be a single string. But mostly you use quotes only if you are passing a argument that has spaces inside like:

mkdir "My Documents"

这将创建一个名为我的文档"的目录.另外,您可以逃脱这样的空间.

That creates a single directory named My Documents. Also, you could escape spaces like this.

mkdir My\ Documents

但是请记住,"$"是一个特殊字符,例如"\".外壳将其解释为变量.执行之前,"$ a"将被其值替换.如果您使用简单的引号('$ a'),则shell不会对其进行解释.

But remember, "$" is a special character like "\". It gets interpreted by the shell as a variable. "$a" will be substituted by its value before executing. If you use a simple quote ('$a') it will not be interpreted by the shell.

此外,&"是在后台执行命令的特殊字符.您可能还应该将其传递给引号之外.

Also, "&" is a special character that executes the command in background. You should probably pass it outside the quotes also.

这篇关于Bash“未找到命令"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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