Skip to main content

How Do You Pause A Script?

by
Last updated on 3 min read

Stuck with a script that’s flying through commands too fast? You’ve got two solid options: pause for a manual stop or sleep for a timed delay.

What’s Happening

When you need to pause a script mid-run, you're usually trying to read output, wait for a process, or check something before it continues.

Running a script in Windows Command Prompt (cmd.exe) or PowerShell? You might want to pause execution to catch messages or inspect things before it keeps going. In a classic .bat or .cmd file, pause is built right in. Unix-like shells (Linux, macOS Terminal, WSL) don’t have a single “pause” command, so you’ll use sleep or read instead. Try typing pause in Bash, and you’ll just get “command not found”—that’s why the right tool matters for the right system.

Step-by-Step Solution

Pause a Windows Batch Script

To pause a Windows batch script, you’ll use the built-in pause command, which halts execution until you press a key.
  1. Open Command Prompt (press Win + R, type cmd, then hit Enter).
  2. Head to your script folder: cd C:\Scripts
  3. Create or edit pause_demo.cmd in Notepad:
    @echo off
    echo Starting backup...
    pause
    echo Backup complete.
  4. Save the file and run it: pause_demo.cmd
  5. The script stops at pause and waits for any key. Press any key to continue.

Pause a Shell Script on Linux/macOS/WSL

For Unix-like systems, sleep is the go-to for timed pauses in shell scripts.
  1. Open a terminal.
  2. Create sleep_demo.sh with this content:
    #!/bin/bash
    echo "Waiting 5 seconds..."
    sleep 5
    echo "Done waiting."
  3. Make it executable: chmod +x sleep_demo.sh
  4. Run it: ./sleep_demo.sh

Pause a Shell Script Until User Presses Enter

If you want the script to wait for user input before continuing, use read to pause until Enter is pressed.
  1. Edit the same file:
    #!/bin/bash
    echo "Press Enter to continue..."
    read -r
  2. Run it again. The script halts until you press Enter.

If This Didn’t Work

If your pause command isn’t behaving as expected, here’s how to troubleshoot common issues.
  • On Windows: Want to hide the “Press any key to continue…” message? Just add nul to the pause command: pause >nul. It still waits for a keypress but keeps the prompt clean.
  • On Linux/macOS: If sleep isn’t recognized, you might not be using Bash. Try read -p "Press Enter to continue..." or install coreutils if it’s missing.
  • Keyboard stuck? If the Pause key on your keyboard isn’t responding, your system might be intercepting it. Try Ctrl+S to pause output or fall back on the step-by-step method above.

Prevention Tips

To keep your scripts running smoothly, follow these best practices for pausing and delays.

Want to avoid messy batch script surprises? Start with @echo off so only your messages show up, not every command being executed. Need a 5-second delay without user input? timeout /t 5 works great for automated installs. In Bash scripts, always quote variables ("$var") and test with #!/bin/bash shebang to dodge silent failures. Keep a simple test script handy: echo Hello && pause (Windows) or #!/bin/bash echo Hello; read -r (Linux). Run it whenever you tweak your environment—it’s a lifesaver.

Alex Chen
Author

Alex Chen is a senior tech writer and former IT support specialist with over a decade of experience troubleshooting everything from blue screens to printer jams. He lives in Portland, OR, where he spends his free time building custom PCs and wondering why printer drivers still don't work in 2026.

How Do You Set A Picture As Your Background On IMVU?How Do You Use Hereinafter?