所以我刚刚开始学习 grep 并尝试在 WSL Ubuntu 上使用它。但某些 grep 命令不提供任何输出,例如 grep '123$'sampledata.txt 行 - 不提供任何输出。当我在我的 Azure 虚拟机上尝试这个时,它工作正常。还有其他人面临这个问题吗?有什么办法可以解决这个问题。
谢谢。
#!/bin/bash
read -p "enter search term here: " searchT
if [[ $(cat test.txt | grep -wi '$searchT') ]]; then
echo "$(cat test.txt | grep '$searchT' && wc -l) number of matches found"
echo $(cat test.txt | grep '$searchT')
else echo "no match found"
fi
exit 0
Run Code Online (Sandbox Code Playgroud)
如果if statement为真,我如何使脚本运行。当我运行脚本时,脚本将输出else语句。因为没有值可以与 grep 命令进行比较。