[英]Bash script using find and grep
I am using bash script to match certain words but it's not working, it should give me color output using grep command.我正在使用 bash 脚本来匹配某些单词,但它不起作用,它应该使用 grep 命令给我颜色 output。
warrior(){
echo ""
for i in ${sources[@]}
do
echo ""
echo ""
a=$(grep -n "\$_${i}" $f | grep -o "\$.*=" | sed "s/[ ]\?=//g" | sort -u)
for j in ${sinks[@]}
do
grep --color -n "${j}.*\$_${i}" $f
for k in $a
do
grep --color -n "${j}.*$k" $f
done
done
done
}
if [ $f != "-r" ]
then
warrior
else
for i in $(find $2 -type f -name "*.*")
do
echo "File: $i"
f=$i
warrior
done
fi
Expected output:预期 output:
14: document.getElementById('p1').innerHTML = 'Hello, ' + username + '!';
36: document.getElementById('p1').innerHTML = 'Current market index is ' + market.index + '.';
Error output:错误 output:
./myprog.sh test
- empty results
All code is ok, error was grep -o and sed commands were extra also \$_ was being interpreted as EOL by grep, deleting it, fixed the issue.所有代码都正常,错误是 grep -o 和 sed 命令是额外的,\$_ 被 grep 解释为 EOL,删除它,修复了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.