Dynamic Execution
Run same script with different inputs.
Shell Script · Script Arguments
Shell Scripting · Lesson 16
Pass arguments to shell script from command line. Use $1 $2 and special variables. Create flexible admin scripts. Production style usage.
Script arguments are values passed to a shell script when it is executed. They allow scripts to behave dynamically based on user input.
Run same script with different inputs.
Useful in automation and batch scripts.
Easily manage multiple input values.
$0 – Script name$1 – First argument$2 – Second argument$# – Number of arguments$@ – All arguments individually$* – All arguments as a single stringPass arguments while running the script from terminal.
Use $# to get total number of arguments.
Use $@ or $* to access all arguments.
Iterate through all arguments using a loop.
Shift removes the first argument and shifts others.
Next lesson: Exit Status & Error Handling