You can use $# to check the number of arguments passed to your script. To access individual arguments, use $1 for the 1st argument, $2 for the second argument so on and so forth.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
## Create a script cat << 'EOF' > file.sh #!/bin/bash if [ $# -eq 0 ];then echo "No arguments supplied" else echo "$# arguments passed of which 1st argument is $1" fi EOF ## Execute the script (without arguments) ./file.sh ## Returns No arguments supplied ## Execute the script (with arguments) ./file.sh 1 2 3 4 ## 4 arguments passed of which 1st argument is 1 |