現在のディレクトリでファイルを検索し、ファイルがディレクトリにある場合はtrueと評価し、ファイルが存在しない場合はfalseと評価する次のスクリプトがあります。
#!/bin/bash
printf "\n Please enter a file name "
read num3
if [ -f $num3 ]
then
printf "It is valid script "
else
printf "Invalid file name "
fi
スクリプトが作成された現在のディレクトリ以外のディレクトリにファイルがあるかどうかを確認できますか?
ベストアンサー1
この試み
#!/bin/bash
printf "\n Please enter a file name "
read num3
printf "\n Please enter the path to check "
read path2check
if find $path2check -name $num3 -print -quit |
grep -q '^'; then
echo "the file exists!"
else
echo "the file does not exist!"
fi