Linux Bash Exit Code 2 — Misuse of Shell Builtin
Warningbash errors
Overview
Bash exit code 2 indicates incorrect usage of a shell builtin command, typically due to wrong arguments or syntax errors.
Key Details
- Exit code 2 is defined by bash for misuse of shell builtins
- Often appears when passing invalid options or arguments
- Many GNU utilities also return 2 for usage errors
- Different from exit code 1 (general error) in that it specifically indicates wrong usage
- The command was found and executed but rejected the arguments
Common Causes
- Invalid command-line option or flag
- Missing required argument for a command
- Incorrect syntax in shell built-in (test, [, [[)
- Wrong number of arguments to a function
- Unrecognized option passed to a GNU utility
Steps
- 1Read the command usage: command --help or man command
- 2Check the exact syntax — some flags require = sign or spaces
- 3Verify option flags match the installed version of the command
- 4Use the long form of options for clarity: --verbose instead of -v
- 5Check if the command is a shell builtin or external: type command_name
Tags
linuxbashexit-code-2usagebuiltin
More in Bash Errors
Frequently Asked Questions
Commands built into bash itself (cd, echo, test, [, source, export) as opposed to external programs like ls or grep.