Aliases and prompt configuration
An alias replaces an eligible command word during parsing, before normal command lookup. Interactive Bash normally expands aliases; a noninteractive script must enable shopt -s expand_aliases if it deliberately uses them. Define an alias on an earlier complete input line, not in the same parsed compound command. Aliases do not receive their own positional arguments: use functions for reusable parameterized logic. unalias name removes a definition. PS1 is the primary interactive prompt and PS2 is the continuation prompt. Prompt escapes such as \w represent the working directory. Bash 5.2 supports ${PS1@P} for prompt expansion; PROMPT_COMMAND may execute commands before each primary prompt, including array entries. With promptvars enabled, prompt text can trigger additional expansions; never use untrusted prompt code or expensive network commands. Configure only a disposable interactive shell, and use functions instead of aliases in scripts. Prompt rendering in an actual terminal is a separate manual lab. The fixed prompt expansion is not a test of PROMPT_COMMAND execution or actual Readline rendering. Alias removal and the enable operation should also be checked.
Practical examples
Run each example as a separate script in a fresh noninteractive Bash 5.2 process and empty practice directory. Tests use C locale; do not enter expected output as code.
Enable and expand an alias
shopt -s expand_aliases || exit 1alias bmhello='printf "%s\n" hello' || exit 1bmhellounalias bmhello || exit 1if alias bmhello >/dev/null 2>&1; then exit 1; fiExpected stdout:
helloThe alias is defined before the following line is parsed; removal is verified.
Use a function for arguments
report() { printf '[%s]\n' "$@"; }report 'daily report' Expected stdout:
[daily report]A function receives its own argument vector.
Expand a fixed prompt string
PS1='practice> 'PS2='continue> 'printf '[%s]\n' "${PS1@P}" "$PS2"Expected stdout:
[practice> ][continue> ]A fixed primary prompt is expanded without waiting for terminal input.
Common mistakes
Do not define and invoke an alias on one parsed line; do not rely on aliases for function-style arguments. Avoid command substitutions in prompt text from untrusted sources.
Practice
Define a harmless alias on its own line, inspect it with alias, remove it, then replace it with a function that prints each supplied argument separately.
Next: Readline, history and bindings