Bash yes/no Script Continuation Confirmation

Confirming Script Continuation with Yes/No in Bash

How to confirm script continuation with yes/no in Bash on Linux command line.

Shou Arisaka
1 min read
Nov 22, 2025

How to confirm script continuation with yes/no in Bash on Linux command line.

Image

I made the following script clearer and easier to use.

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

}

Usage example

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

Share this article

Shou Arisaka Nov 22, 2025

๐Ÿ”— Copy Links