找不到命令 [英] Command not found

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

问题描述

我赶上了在说一个问题。

I am caught up in a problem which says.

./ 212A1.sh:line327:[[10:找不到命令
...(和10+更多我想这同样的错误是由于记录的打印输出。

./212A1.sh: line327: [[10: command not found ...(and 10+ more of the same errors i guess this is due to the printout of the record.

这是我的code线路327。

This is my code for line 327.

if [[$QtyAvailable -eq $lowStockMargin && $QtyAvailable -lt $lowStockmargin]]

一切完美,直到我最近刚刚打开我的Ubuntu和开始再次运行我的程序。我没有在该行编辑任何东西。

Everything works perfectly until I just recently opened my Ubuntu and started to run my program again. I did not edit any thing on that line.

#!/斌/庆典在文件的第一行仍然声明。

#!/bin/bash is still declared at the first line of the file.

在此先感谢那些谁帮助! :)

Thanks in advance to those who helped! :)

 read -p $'Please kindly key in the margin for low stock: \033[4m' lowStockMargin
printf '\033[0m'

grep "$1" BookDB.txt |
while IFS=: read Title Author Price QtyAvailable QtySold;
do
    #compare user input with every extracted line with the qtyavailable variable
    if [[ $QtyAvailable -eq $lowStockMargin && $QtyAvailable -lt $lowStockMargin ]]
    then
    #if condition is passed, then print information of the book
    printf "%-50s %-16s %-14s %-15s %-13s %s\n" "$Title" "$Author" "$Price" "$QtyAvailable" "$QtySold" "$(echo $QtySold*$Price | bc)"
    fi
done

SOLUTION

我改变了我行
    如果(($ QtyAvailable&下; = $ lowStockMargin));
并制定了罚款。

I changed my line to if (( $QtyAvailable <= $lowStockMargin )); and it worked out fine.

感谢您的输入家伙。

推荐答案

该问题是在这里:

[[$QtyAvailable

在shell脚本 [是一个命令令牌本身。因此,对于这个标记的规则,像任何其他应用。即,你需要的空白。所以,你应该有这样的:

In shell script [[ is a command token itself. Thus the rules for this token, like any other, apply. i.e., you need whitespace. So you should have this as:

[[ $QtyAvailable

有在该行的末端有类似的问题。 - ]] 需要由它自己站立,而不是接合到其它文本

there's a similar problem at the end of the line -- ]] needs to stand by itself and not be joined to other text.

这样做的原因追溯到原始伯恩壳的日子。击的 [只是原来的Bourne shell的 [命令的扩展。早在t'day,(当这一切被田野和我只是一个孩子,牙龈EE), [是一个外部命令,本身就是一个符号链接到外部测试

The reason for this goes back to the days of the original bourne shell. Bash's [[ is just an extension of the original bourne shell's [ command. Back in t'day, (when all this were fields and I were just a lad, ee by gum), [ was an external command, itself a symbolic link to the external test.

最后, [成为内置了壳,但语义(即治疗 [作为一个独立的命令),因为它需要(至少是)为了向下兼容所以SH它被内置能在这些地方并没有内置的运行编写的脚本依然存在。所以,现在我们期待现在跳到和相同的语义依然存在。它还具有bash的维护者一个实际的好处:寻找 [ [作为一个独立的标记是一个简单的行使。介绍其他字符作为分隔符,它增加了复杂性(不是很多,但也足够)。

Eventually [ became a shell built-in, but the semantics (i.e., treating [ as a standalone command) remained as it was needed (at the very least) for backwards compatibility so scripts written for sh where it was built-in could run on those where it wasn't built-in. So now we skip forward to now and the same semantics remain. It also has a practical benefit to the bash maintainers: looking for [ or [[ as a standalone token is a straightforward exercise. Introduce other characters as delimiters and it adds complexity (not a lot, but enough).

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

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