← All commands
Topic hub Terminal & Shell Scripting
Windows Linux Terminal & Shell Scripting Expanded guide Terminal

Windows %errorlevel% equivalent in Linux

Reads the exit status of the last command. 0 means success; any non-zero value means failure.

Windows %errorlevel%
→
Linux equivalents
Debian/Ubuntu same command
$?
Fedora same command
$?
Arch same command
$?

Overview

What this command does

On Windows, "%errorlevel%" is used to check command success or failure exit code. On Linux, the closest practical mapping shown here is "$?". Reads the exit status of the last command. 0 means success; any non-zero value means failure. This reference is grouped under Terminal & Shell Scripting → Terminal.

Migration tip: <code>$?</code> holds the exit code of the last command. Use <code>&&</code> to chain commands that only run on success, and <code>||</code> for failure. <code>set -e</code> makes a script exit immediately on any error.

Windows → Linux context

What changes when you use this on Linux?

Equivalent task, different tool

Windows %errorlevel% maps to $? for this task. Treat this as a workflow mapping rather than a character-for-character syntax translation.

Portable across the compared distros

The Debian/Ubuntu, Fedora and Arch rows use the same command in this mapping. Package availability or defaults can still vary, so check the installed tool version when an option behaves differently.

Practical tasks

Common use cases

Check command success or failure exit code

Reads the exit status of the last command. 0 means success; any non-zero value means failure.

$?

Exit code of last command (0=success)

cmd1 && cmd2

Run cmd2 only if cmd1 succeeded

cmd1 || cmd2

Run cmd2 only if cmd1 failed

Ready to run

Copyable Linux commands

Review paths, device names, package names and permissions before running any command.

ls /tmp
echo $?
ls /nonexistent
apt update && apt upgrade -y

Walkthrough

Examples with explanations

# Windows: if %errorlevel% neq 0 echo Error

ls /tmp
echo $?     # 0 (success)

ls /nonexistent
echo $?     # 2 (error)

# Chain commands:
apt update && apt upgrade -y

Reference

Common options and variations

Command or optionUse
$?Exit code of last command (0=success)
cmd1 && cmd2Run cmd2 only if cmd1 succeeded
cmd1 || cmd2Run cmd2 only if cmd1 failed
set -eExit script on first error
set -o pipefailCatch errors inside pipes

Distro differences

Debian/Ubuntu vs Fedora vs Arch

Debian/Ubuntu, Fedora and Arch all use "$?" for this mapping. The command syntax shown here is portable across the three rows, although installed versions and system defaults can still vary.

DistributionPackage manager / baseEquivalent commandDifference to notice
Debian/Ubuntu same command $? Same command on this distribution.
Fedora same command $? Same command on this distribution.
Arch same command $? Same command on this distribution.

Keep learning

Related Terminal & Shell Scripting commands