错误的shell脚本,如果条件 [英] Error in shell script if condition
本文介绍了错误的shell脚本,如果条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不明白他的错误是在这里IAM新shell脚本。请帮我
./ BPR:8号线:附近意外的标记语法错误'然后'
./bpr:8号线:`如果[$(grep的-o BPR $文件|厕所-l)== 1];然后 '
解决方案
您需要一个空间,在你的条件:
如果[$(grep的-o BPR $文件|厕所-l)== 1];然后
^^
1)如果你正在使用bash,您可以使用内置的 [[..]]
而不是测试
( [...]
)命令。
2)您也可避免厕所
使用 -c
的grep的选项。
如果[[$(grep的-c -o BPR $文件)== 1]];然后
I didnt understand what he error here as iam new to shell scripting. Please help me
./bpr: line 8: syntax error near unexpected token `then'
./bpr: line 8: ` if[$(grep -o BPR $file | wc -l) == 1]; then '
解决方案
You need a space around your condition:
if [ $(grep -o BPR $file | wc -l) == 1 ]; then
^ ^
1) If you are using bash, you can use the built-in [[ ..]]
instead of test
([ ...]
) command.
2) You can also avoid wc
by using -c
option of grep.
if [[ $(grep -c -o BPR $file) == 1 ]]; then
这篇关于错误的shell脚本,如果条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文