Bash ja/nein Skript Fortsetzung Bestätigung

Skriptfortsetzung mit Ja/Nein in Bash bestätigen

Wie man die Skriptfortsetzung mit Ja/Nein in Bash auf der Linux-Befehlszeile bestätigt.

Shou Arisaka
1 Min. Lesezeit
4. Okt. 2025

Wie man die Skriptfortsetzung mit Ja/Nein in Bash auf der Linux-Befehlszeile bestätigt.

Image

Ich habe das folgende Skript klarer und einfacher zu verwenden gemacht.

How do I prompt a user for confirmation in bash script? - Stack Overflow


ok(){

  : <<< '
  yes or no prompt
  e.g. printf "The file alredy exist here. Overwrite it? " ; ok && echo y || echo n
  '

  read -n 1 -r ; [[ $REPLY =~ ^[Yy]$ ]] && return 0 || return 1

}

Verwendungsbeispiel

printf "The file alredy exist here. Overwrite it? " ; ok && echo y || echo n

Diesen Artikel teilen

Shou Arisaka 4. Okt. 2025

🔗 Links kopieren