Bash aliases are simple text substitutions; they are expanded when the command line is read, not when it is executed. Positional parameters such as $1 therefore have no meaning inside an alias, so the expansion produces tar -czf .tgz project, leaving an empty archive name and causing tar to fail. A shell function runs in the current shell and can reference $1, $2, and so on at execution time. Replacing the alias with a function such as backup() { tar -czf "$1.tgz" "$1"; } provides the required behaviour. Escaping the dollar signs only defers expansion until after alias substitution (the parameters are still undefined), moving the definition to another startup file does not add argument capability, and there is no -E option to make alias handle parameters.
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.
Why can't aliases in Bash handle positional parameters like $1?
Open an interactive chat with Bash
What is the main difference between a Bash alias and a shell function?
Open an interactive chat with Bash
How does escaping the dollar signs in an alias definition still fail to make it work?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
System Management
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .