Skip to main content

How Do You Pause A Script?

by
Last updated on 6 min read
Quick Fix Summary
On Windows, drop pause on any line. On Linux/macOS shell, use read -r or sleep N where N = seconds.

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.

A script blasts through commands faster than you can blink. Pausing gives you time to inspect logs, wait for a process to finish, or decide if you want to keep going. Windows has a built-in pause that literally waits for a keypress. Unix-like systems don’t have one magic “pause” command, so you pick either sleep for fixed delays or read to wait for Enter. Type pause in Bash, and you’ll just get “command not found.” The right command depends entirely on which shell you’re using.

Step-by-Step Solution

Pause a Windows Batch Script (.cmd / .bat)

Add pause on any line to halt the script until you press a key.
  1. Open Command Prompt: press Win + R, type cmd, hit Enter.
  2. Change to your script folder: cd /d "C:\Scripts"
  3. Create test.cmd in Notepad:
    @echo off
    echo Starting backup at %time%
    pause >nul
    echo Backup complete.
  4. Save the file and run it: test.cmd
  5. It stops at pause >nul; press any key to continue.

Add a Fixed Delay in a Shell Script (Linux/macOS/WSL)

Use sleep 3 (or any number) to wait exactly N seconds before the next command runs.
  1. Open Terminal.
  2. Create delay.sh:
    #!/bin/bash
    echo "Waiting 3 seconds..."
    sleep 3
    echo "Done."
  3. Make it executable: chmod +x delay.sh
  4. Run it: ./delay.sh

Wait for User Confirmation in a Shell Script

Insert read -rp "Press Enter to continue… " -n1 to pause until the user presses Enter.
  1. Edit the same file:
    #!/bin/bash
    read -rp "Press Enter to continue… " -n1
  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, check these common fixes.
  • Windows: Want to hide the “Press any key…” prompt? Use pause >nul. It still waits for a keypress, just without the extra text.
  • Linux/macOS: If sleep throws “command not found,” install coreutils: sudo apt update && sudo apt install coreutils Ubuntu source.
  • Keyboard Pause key not working: Try Ctrl+S to freeze terminal output, then Ctrl+Q to resume. If you need a script-level pause, fall back to the steps above.

Prevention Tips

Start every batch file with @echo off to keep the output clean.

Begin every batch file with @echo off so only your messages appear. Swap manual waits for timeout /t 5 when you need unattended delays. In Bash scripts, always use #!/bin/bash as the first line and quote variables ("$var"). Keep a tiny test file on your desktop—echo Test && pause >nul on Windows or #!/bin/bash; echo Test; read -r on macOS/Linux—and run it after every toolchain change to catch environment issues early.

Why does pause behave differently on Windows versus Unix-like systems?

Windows has a built-in pause command, while Unix-like systems rely on sleep or read.

Windows Command Prompt treats pause as a first-class citizen—it literally waits for a keypress. Unix-like shells never got that luxury, so they ship with sleep for fixed delays and read for waiting on user input. Type pause in Bash, and you’ll just get “command not found.” That’s why the command you pick depends entirely on which system you’re running.

Can I pause a script without user interaction?

Yes—use sleep N for a fixed delay or timeout /t N on Windows.

If you don’t want to babysit the script, insert a fixed delay. In Bash that’s sleep 5 for five seconds of waiting. On Windows you can use timeout /t 5 (it even shows a countdown). Both methods let the script run hands-free until the timer expires.

How do I hide the “Press any key to continue” message on Windows?

Append >nul to the pause command.

Add pause >nul to your script and the prompt disappears—yet it still waits for a keypress. It’s the same behavior, just cleaner output.

What’s the difference between sleep and read in Bash?

sleep waits a fixed number of seconds; read waits for user input.

sleep 10 pauses for ten seconds, no questions asked. read halts until the user presses Enter (or supplies a single character with -n1). Use sleep for timed waits and read when you need confirmation.

Why does sleep say “command not found” on my Linux system?

You may need to install the coreutils package.

Most Linux distributions ship sleep as part of the coreutils package. If it’s missing, run sudo apt update && sudo apt install coreutils Ubuntu source to get it.

How can I pause a PowerShell script?

Use Read-Host or Start-Sleep.

PowerShell doesn’t have a pause built-in, but you can mimic it. For a keypress wait, use $null = Read-Host "Press Enter to continue". For a fixed delay, try Start-Sleep -Seconds 5.

Is there a way to pause a script only if a certain condition is met?

Wrap the pause command in an if statement.

In Bash you can do if [ "$error" = "1" ]; then read -rp "Error detected—press Enter to continue"; fi. In Windows batch you’d use if %errorlevel% neq 0 pause. The script only pauses when your condition is true.

Can I pause a script and still see the last few lines of output?

Use more or redirect to a file before pausing.

Before you pause, pipe the output to more or save it to a file. For example, your_command | more lets you scroll through the last screenful before the script halts. Or redirect to a file, review it, then add your pause.

What’s the shortest pause I can create in a shell script?

Use read -t 1 to wait up to one second for Enter.

Bash’s read -t 1 waits one second for input; if nothing arrives, it continues automatically. That’s about as short as you can get without diving into sub-second timers.

How do I pause a script running in the background?

Bring it to the foreground with fg and then pause it.

If your script is already running in the background, type fg to bring it to the foreground. Once it’s in the foreground you can add a read or sleep command directly in the script, or press Ctrl+Z to suspend the process entirely.

Can I pause a script at a specific line number?

Insert the pause command on the exact line you want to halt.

Open the script, drop pause (Windows) or read (Bash) on the line where you want execution to stop, save, and rerun. The script will pause precisely at that spot.

What’s the best way to pause a Python script?

Call input() or time.sleep(N).

In Python you can pause for user input with input("Press Enter to continue"). For a fixed delay, import the time module and use time.sleep(5). Both methods give you full control over when (and if) the script resumes.

Edited and fact-checked by the TechFactsHub editorial team.
Alex Chen
Written by

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?