假设我在 bash 中有以下代码:
#!/bin/bash
bad_fruit=( apple banana kiwi )
for fname in `ls`
do
# want to check if fname contains one of the bad_fruit
is_bad_fruit=??? # <------- fix this line
if [ is_bad_fruit ]
then
echo "$fname contains bad fruit in its name"
else
echo "$fname is ok"
fi
done
如何修复 is_bad_fruit 以确保 fname 包含 bad_fruit 字符串之一?