[grep] how to use grep return value as if condition
# The $? holds the exit status of the previously executed command. Check the man page please. for item in *.json; do # grep "perl" "$item" > /dev/null #为了不在屏幕上显示grep结果 # 或者: grep -q "perl" "$item" if [ $? -eq 0 ]; then #如果搜索到perl,则$?会是0,否则为1 echo $item #输出含有perl的文件,对应的文件名 fi done