[bash]指定ファイル名を削除するサンプル

書式
if[ -f ファイル名 ]
then rm ファイル名
else 処理コード
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
echo "Enter the file name: "
read fn
if [ -f $fn ]
then rm $fn
else echo "No such file"
fi
echo "Enter the file name: " read fn if [ -f $fn ] then rm $fn else echo "No such file" fi
echo "Enter the file name: "
read fn
if [ -f $fn ]
then  rm $fn
else  echo "No such file"
fi

実行結果
#./test.sh
Enter the file name:
file.txt

batch

Posted by arkgame