You can use $# environment variable to check number of arguments passed to a Linux Bash script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
## Create a bash script cat << 'EOF' > file.sh #!/bin/bash echo "Script No. Of Arguments = $#" echo "Script Arguments = $@" myfun() { echo "Function No. Of Arguments: $#" echo "Function Arguments: $@" } myfun $1 $2 $3 $4 EOF ## Execute the bash script with arguments ./file.sh 1 2 3 4 ## returns ## Script No. Of Arguments = 4 ## Script Arguments = 1 2 3 4 ## Function No. Of Arguments: 4 ## Function Arguments: 1 2 3 4 |