Find what will execute
Inspect all definitions of the name. Before following an example, check whether the command has been overridden.
A command interpreter for interactive input, builtins, and shell scripts.
bash --version
shell version
help
builtin help
type pwd
command type
help pwd
command help
set -o
shell options
history
session history
bash is a shell: a program that interprets a command language and arranges
execution. The terminal handles input and display; Bash decides how to execute the
entered line. Script construction is covered separately in bash-scripting.
A command may be a builtin, function, alias, or external program. Finding an
executable with a matching name does not establish that it will be selected. Use
type to inspect command resolution. The cd builtin changes the current shell
directory; a separate process cannot change its parent session’s directory.
Distinguish bash invocation options from set options and shopt settings: these are
separate interfaces, not one flat option list. bash script.sh runs a script in
another shell. source script.sh runs it in the current one and can change its
variables or directory.
Use set -o to inspect shell options and shopt to inspect additional settings.
These diagnostic invocations do not change the mode. Before copying settings from
an example, identify which shell should receive them.
| Option | What it does | Example |
|---|---|---|
-c command |
Execute command as a string and exit, without reading a script file. | bash -c 'echo hi' |
-x |
Print each command before running it (xtrace). | bash -x script.sh |
-e |
Exit on the first command with a non-zero exit status (same as set -e). | bash -e script.sh |
-i |
Start an interactive shell even when input is not a terminal. | bash -i |
-l --login |
Behave as a login shell (read the system profile and one user profile). | bash -l |
-n |
Check the script's syntax only, without executing it. | bash -n script.sh |
--noprofile |
Skip the system and per-user profile files for a login shell. | bash --noprofile |
--norc |
Skip ~/.bashrc for an interactive non-login shell. | bash --norc |
--version |
Show the bash version and exit. | bash --version |
Nothing found. Try a shorter query.
Inspect all definitions of the name. Before following an example, check whether the command has been overridden.
set -o lists option states, including emacs and vi. The introductory lesson assumes Emacs editing mode.
In emacs mode (on by default), you edit the line before Enter with these keys:
| Keys | What they do |
|---|---|
| Ctrl+A / Ctrl+E | cursor to the start / end of the line |
| Alt+B / Alt+F | one word back / forward |
| Alt+Backspace | erase the word before the cursor |
| Ctrl+U | erase everything before the cursor |
| Ctrl+K | erase from the cursor to the end of the line |
| Ctrl+Y | paste back the last erased text |
| Ctrl+R | search the command history |
| Ctrl+L | clear the screen |
Text erased with Alt+Backspace, Ctrl+U and Ctrl+K isn't lost: Ctrl+Y pastes it at the cursor. That's how you move part of a command: Ctrl+U, then edit, then Ctrl+Y.
In a browser terminal Ctrl+W closes the tab, so erase words with Alt+Backspace. If Alt+B or Alt+F types a character instead of moving (it happens on macOS), use the arrow keys.
An interactive non-login shell reads ~/.bashrc. A login shell reads the system profile and the first available user profile among ~/.bash_profile, ~/.bash_login, and ~/.profile. Do not infer the mode solely from how a terminal window was opened; Ubuntu also has system configuration.
Check spelling and command lookup. Starting another Bash does not install a missing program.
Identify the session mode and relevant startup file. Do not source an unreviewed file merely to diagnose loading behaviour.
History belongs to a shell session and its configuration. Inspect its state; printing settings does not recreate missing entries. Do not publish a whole history, which may contain secrets.
Danger. Text passed to
bash -cand files read by source are executed, not merely displayed.bash -nchecks syntax, not safety. Avoid tracing secret-bearing commands into shared logs. Do not treat set -euo pipefail as a correctness guarantee: behaviour depends on context and failures need deliberate handling.
bash-scripting — variables, conditions, and scripts.
env-vars — environment and PATH.
man-help — finding the right help.
pwd — the shell’s current directory.
files-basics — basic terminal and file operations.
command-syntax — how the shell splits a line into a command, options and arguments.
redirection — output redirection and pipelines.
Found an inaccuracy? Report an error in the article