Skip to content

The Deska blog

Confirmation Prompts in Scripts: Are You Sure You Are Sure

Learn best practices for designing confirmation prompts in scripts to prevent data loss and improve CLI usability without breaking automation workflows.

10 min read

Designing command line tools requires a delicate balance between efficiency and safety. When a developer executes a command that modifies state, deletes files, or triggers a production deployment, the software must ensure the intent is intentional. Mastering the use of confirmation prompts in scripts is essential for creating robust CLI applications that protect users from accidental destructive actions while remaining compatible with non-interactive environments.

The Psychology of the Confirmation Prompt

Confirmation prompts act as a circuit breaker for the human brain. Developers often work in a state of flow where muscle memory takes over. A typo in a variable or a misunderstood flag can lead to irreversible consequences. By interrupting the execution flow, you force the user to switch from fast, intuitive thinking to slow, logical processing.

However, overusing these prompts leads to confirmation fatigue. If every minor action requires a manual "yes", users will eventually type "y" or "yes" reflexively without reading the warning. This defeats the entire purpose of the safety check. The goal is to reserve prompts for truly high stakes operations where the cost of a mistake outweighs the friction of an extra keystroke.

Core Principles for CLI Safety

A well designed CLI should follow several key principles to handle user intent effectively. These rules ensure that your scripts are both safe and professional.

  • Defaults should be safe. If a user hits Enter without typing anything, the script should assume a "No" or "Cancel" response.
  • Explicit is better than implicit. For extremely dangerous actions, such as dropping a database, require the user to type a specific word like "DELETE" rather than just a single letter.
  • Context is everything. Show the user exactly what is about to happen. Instead of asking "Are you sure?", ask "Are you sure you want to delete 45 files in /tmp/logs?".
  • Respect the environment. Always provide a way to bypass prompts for automated CI/CD pipelines.

Handling Non-Interactive Environments

Scripts often run in environments where no human is present to answer a prompt. If your script detects that it is not running in a TTY (Teletype), it should behave differently. Failing to handle this can cause a CI/CD pipeline to hang indefinitely as it waits for input that will never come.

The standard approach is to implement a force flag. Most developers expect -f or --force to skip safety checks. Alternatively, a --yes or -y flag indicates that the user has already provided consent via the command line arguments.

Implementing Confirmation in Shell Scripts

Writing a reliable prompt in a shell script requires more than a simple read command. You must account for case sensitivity and unexpected input.

# A robust confirmation pattern
read -p "Do you want to proceed? (y/N): " response
case "$response" in
    [yY][eE][sS]|[yY]) 
        echo "Proceeding..."
        ;;
    *)
        echo "Operation cancelled."
        exit 1
        ;;
esac

This pattern ensures that only an explicit positive response allows the script to continue. Anything else, including a blank Enter key, results in a safe exit.

Visualizing Script Execution with Deska

When managing complex workflows involving multiple scripts and AI agents, the interface where you run these commands matters. Deska provides an infinite canvas workspace where you can arrange multiple terminals alongside your code. This layout allows you to see the script logic in one panel while monitoring the execution in another.

If you are using coding agents like Claude Code or Codex CLI within Deska, you can run them in side by side panels. When an agent generates a script, you can review it in the built in Monaco code editor before running it in a terminal panel. This visual proximity reduces the cognitive load and helps you spot missing confirmation prompts or dangerous logic before execution.

The Ask Deska assistant can also help manage your workspace sessions. You can use voice or chat to open new panels or check the status of a running script across your canvas. Because Deska is local-first, all your terminal sessions and script outputs remain on your machine, ensuring that sensitive confirmation logs are never uploaded to a third party server.

Comparison of Prompt Strategies

Different tools use different methods to confirm dangerous actions. Choosing the right one depends on the severity of the action.

StrategyUser EffortSafety LevelBest Use Case
Simple FlagLowLowMinor changes, high frequency tasks
Y/N PromptMediumMediumDeleting non-critical files, stopping services
String MatchingHighHighDropping databases, production deploys
Dry Run ModeLowVery HighTesting complex migrations or bulk edits

A "Dry Run" mode is often superior to a prompt for complex operations. By using a --dry-run flag, users can see the exact outcome of their command without any changes being applied. This builds confidence and often removes the need for a nervous confirmation at the end.

Avoiding Common Pitfalls

One common mistake is placing the confirmation prompt too late in the process. If a script performs five minutes of read-only analysis and then asks for confirmation before a one-second write operation, the user may have walked away. Always prompt as early as possible after the necessary context has been gathered.

Another pitfall is inconsistent naming of bypass flags. Stick to industry standards. If your tool uses --confirm to skip a prompt while every other tool uses --yes, you are creating a trap for your users.

Frequently Asked Questions

How to skip confirmation prompts in scripts for CI/CD?

The most common way is to use a flag like -y or --yes if the tool supports it. If the tool does not have a native flag, you can pipe the "yes" command to it using yes | your-script.sh, which automatically answers "y" to every prompt.

Is it possible to detect if a script is interactive?

Yes, in many shell environments you can check if file descriptor 0 (standard input) is a terminal. In Bash, the expression [[ -t 0 ]] returns true if the script is running in an interactive terminal and false if it is being piped or run by a scheduler.

Should I use color in confirmation prompts?

Yes, using color can help distinguish a warning from standard output. Use bold yellow or red for the actual question to catch the user's eye. However, ensure your script still works correctly for users with color blindness or in terminals that do not support ANSI colors.

Building Safer Workflows

Effective confirmation prompts in scripts are a sign of a mature developer tool. They show respect for the user's data and an understanding of human error. By combining these scripting best practices with a powerful environment like Deska, you can build a development setup that is both fast and resilient.

Deska allows you to monitor your scripts even when you are away from your desk. Using the mobile app through a secure relay, you can check the progress of long running tasks and ensure they are not stuck on a forgotten prompt. This local-first approach to remote monitoring keeps your work secure without requiring complex port forwarding.

To experience a more organized way to manage your terminals, agents, and scripts on an infinite canvas, you can download the free desktop app for Mac, Windows, and Linux.

Confirmation Prompts in Scripts: Are You Sure You Are Sure | Deska