Linux for Developers
/Intermediate
Command Line Arguments
Definition
Input parameters passed directly into a script from the terminal when the script is executed, allowing the script to perform dynamically based on the user's input.
Explain Like I'm New
Handing the script instructions before it runs. Instead of hardcoding 'Bob' into the script, you run the script and hand it 'Bob' from the outside.
Real World Example
You write a script `create_user.sh`. Instead of hardcoding the username, you run `./create_user.sh alice`. Inside the script, the variable `$1` magically contains the word 'alice', and the script creates her account.
Common Use Cases
- •Dynamic scripting
- •Creating custom terminal tools
Interview Questions
basic
- In a script, what does the special variable `$1` represent?
intermediate
- What does the special variable `$#` represent in a script?