Bash shell脚本grep以grep字符串

Bash shell脚本grep以grep字符串,bash,grep,Bash,Grep,以下脚本的输出为空。它少了什么?我在试着编一条线 #!/bin/ksh file=$abc_def_APP_13.4.5.2 if grep -q abc_def_APP $file; then echo "File Found" else echo "File not Found" fi 在bash中,使用恶心!使用shell的字符串匹配 if [[ "$file" == *abc_def_APP* ]]; then ... 为什么#!行说ksh?文件的值应该是多少?我

以下脚本的输出为空。它少了什么?我在试着编一条线

#!/bin/ksh    
file=$abc_def_APP_13.4.5.2    
if grep -q abc_def_APP $file; then
 echo "File Found"
else
 echo "File not Found"
fi

bash
中,使用
恶心!使用shell的字符串匹配

if [[ "$file" == *abc_def_APP* ]]; then ...

为什么#!行说ksh?文件
的值应该是多少?我怀疑您可能在该作业的RHS上有问题。如果我使用
If echo$file | grep-q abc_def_APP
它正在打印$file的内容,我不想这样做。您选择
-q
选项以使
grep
在“安静”模式下运行(per);它不应该输出任何东西。如果您的
grep
版本对
-q
有不同的理解,您必须查看您的男士
grep
的手册页,或者重定向到
/dev/null
。您是否有风险将多个文件与
*abc_def_APP*
匹配,并破坏过程中的条件?如果
$file
abc_def_APP1
*abc_def_APP*
扩展到
abc_def_APP1 abc_def_APP2
,则条件将评估为false。关于“恶心!”部分;我完全同意你!整个unix(类unix)命令外壳非常恶心。。。但是你不能没有它,对吗?在双括号内,我们是对左边字符串进行模式匹配,而不是匹配文件名。
if echo $file | grep -q abc_def_APP
file=$abc_def_APP_13.4.5.2
file=abc_def_APP_13.4.5.2
if grep -q abc_def_APP <<< "$file"
if echo "$file" | grep -q abc_def_APP
if [[ "$file" == *abc_def_APP* ]]; then ...