查看以下unix shell脚本:
echo "Enter the pattern to be searched: \c"
read pname
echo "Enter the file to be used: \c"
reac flname
echo "Searching $pname from the file $flname."
grep "$pname" $flname
echo "The search results are displayed above."
请注意grep线。无论$ pname是否用花括号括起来,代码都能正常工作。现在我想尝试awk。
echo "Enter the pattern to be searched: \c"
read pname
echo "Enter the file to be used: \c"
reac flname
echo "Searching $pname from the file $flname."
awk 'BEGIN { FS = ":" }
$3 ~ /"$pname"/' $flname
echo "The search results are displayed above."
现在的问题是:$ pname是否有围绕它的花括号,awk部分不起作用。为什么?有没有办法让awk部分工作?