A systems engineer is writing a Bash script that will run from cron, so the shell is non-interactive. At the top of the script she inserts:
alias ll='ls -Alh'
ll /var/log
When she tests the script it exits with the error ll: command not found. Which single Bash command, placed before the alias definition, will allow the alias to work inside this non-interactive script without further changes?
By default, Bash does not expand aliases when it is running non-interactively. The feature must be explicitly enabled with the shell option expand_aliases. The built-in shopt command is used to turn this option on (-s) or off (-u). Adding shopt -s expand_aliases before any alias definitions causes Bash to treat the script the same way it treats an interactive session for alias expansion, so the subsequent call to ll is replaced by the alias text ls -Alh and the command succeeds.
The other choices do not influence alias expansion:
Exporting BASH_ENV only specifies an initialization file for non-interactive shells; it does not enable alias processing.
set -o noclobber merely prevents redirection from overwriting files.
declare -A ll creates an associative array named ll, which has no effect on how the command name ll is resolved.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the `shopt` command do in Bash?
Open an interactive chat with Bash
Why does Bash not expand aliases in non-interactive shells by default?
Open an interactive chat with Bash
What is the difference between an alias and a shell function in Bash?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Automation, Orchestration, and Scripting
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access