【发布时间】:2013-11-10 11:30:36
【问题描述】:
我在运行简单的 shell 脚本时遇到问题,我在其中使用 while 循环读取文本文件并尝试使用匹配的正则表达式检查条件:
#!/bin/sh
regex="^sometext"
cat input.txt |
{
while read string
do if [[ $string ~= $regex ]]; then
echo "$string" | awk '{print $1}' >> output.txt
else
echo "$string" >> outfile.txt
fi
done
}
但我只收到像
这样的错误[[: not found
你能告诉我吗?
【问题讨论】:
标签: regex shell loops if-statement while-loop