To input arguments into a bash script, like any normal command line program, there are special variables set aside for this
The arguments are stored in variables with a number in the order of the argument starting at 1
The variable $0 is the script's name.
The total number of arguments is stored in $#.
The variables $@ and $* return all the arguments.
Script Example
#!/bin/bash
The arguments are stored in variables with a number in the order of the argument starting at 1
- First Argument: $1
- Second Argument: $2
- Third Argument: $3
- Example
- command: ./script.sh alpha beta gamma
- Variables: $1=='alpha'; $2=='beta'; $3=='gamma'
The variable $0 is the script's name.
The total number of arguments is stored in $#.
The variables $@ and $* return all the arguments.
Script Example
#!/bin/bash
echo "the $1 eats a $2 every time there is a $3" echo "bye:-)"
- Command: ./script.sh dog bone moose
- Output:
the dog eats a bone every time there is a moose bye:-)
Comments
Post a Comment