Unixでの回復機能

Unixでの回復機能

ファイルを元の場所に復元するスクリプトがあります。 「このファイルを復元しますか?」というスクリプトオプションはありません。これを以下のコードにどのように実装しますか?ありがとうございます!

#!/bin/bash
if [[ ! $1 ]]; then
echo -e "Usage:\n\n\t$0 'file name'"
exit 1
fi

f=$(ls 2>/dev/null -l /proc/*/fd/* | fgrep "$1 (deleted" | awk '{print $9}')

if [[ $f ]]; then
   echo "fd $f file found..."
cp -v "$f" "$1"
   else
echo >&2 "No file"
exit 2
fi
 }

ベストアンサー1

確認を要求するために使用されますread。例:

echo "fd $f file found..."
read -p "Press enter to continue or Ctrl+c to cancel"
cp -v "$f" "$1"

または

echo "fd $f file found..."
read -p "Do you want to recover this file? [Yes/No] " confirmation
[[ $confirmation =~ ^[YyJj] ]] || { echo "Canceled"; exit }
cp -v "$f" "$1"

おすすめ記事