Cio*_*res 1 scripts directory find
我希望程序看起来像这样:
read a
if[ find . name $a ]; then
echo "You found the file"
else "You haven t found the file"
fi
Run Code Online (Sandbox Code Playgroud)
无论是否找到任何东西,find
总是返回 true。您可以使用grep
来确定是否find
找到了一些东西:
read -r a
if find . -maxdepth 1 -name "$a" -print -quit | grep -q .
then
echo "You found the file"
else
echo "You haven't found the file"
fi
Run Code Online (Sandbox Code Playgroud)
-print -quit
正如 Eliah 所指出的那样,在第一场比赛 ( )后退出应该会提高性能。用于-maxdepth 1
将结果限制到当前目录 - 但这样find
就显得过分了。