我在下面创建了一个shell脚本,它检查文件out.txt是否包含任何带有文本“Billing_20160210”的行。我得到正则表达式部分中的错误,声明“[[:not found”。不知道我是否缺少一些东西。任何帮助,将不胜感激。使用shell脚本进行正则表达式匹配
#!/bin/bash
bq ls test:Dataset_test > out.txt
cat out.txt | while read LINE
do
if [ LINE = *"Billing_20160210"* ];
then
echo "Processing $LINE"
fi
done
编辑不工作:
#!/bin/bash
bq ls geotab-bigdata-test:JS_test > out.txt
cat out.txt | while read LINE
do
if [[ $LINE == *"DailyBillingTest_20160210"* ]];
then
echo "Processing $LINE"
fi
done
没有正则表达式只是这里glob的。用'[[$ LINE == *“Billing_20160210”*]]替换'[LINE = *'Billing_20160210“*]'' – anubhava
这也是UUOC的情况 – anubhava
'[[:not found'也意味着你不是'实际上使用bash作为你的解释器来运行这个脚本。你用'sh yourscript'来调用它吗?如果是这样,那将覆盖'#!/ bin/bash' shebang。如果使用明确的解释器进行调用,则需要“bash yourscript”而不是“sh yourscript”。 –