【发布时间】:2021-06-21 03:35:44
【问题描述】:
#!/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
如果if statement 为真,我如何使脚本运行。当我运行脚本时,脚本将输出else 语句。因为没有与 grep 命令比较的值。
【问题讨论】:
-
变量
$searchT不会在单引号内展开。改用双引号:"$searchT"