Conoscere quanti parametri vengono passati ad uno script in BASH
Una chicca utile dal buon nixCraft, conoscere quanti parametri vengono passati ad uno script in bash:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#!/bin/bash # Purpose: Demo bash function # Author: nixCraft # ----------------------------- ## Define a function called foo() foo(){ echo "Function name: ${FUNCNAME}" echo "The number of positional parameter : $#" echo "All parameters or arguments passed to the function: '$@'" echo } ## Call or invoke the function ## ## Pass the parameters or arguments ## foo nixCraft foo 1 2 3 4 5 foo "this" "is" "a" "test" |
Questi i risultati a video:
1 2 3 4 5 6 7 8 9 10 11 |
Function name: foo The number of positional parameter : 1 All parameters or arguments passed to the function: 'nixCraft' Function name: foo The number of positional parameter : 5 All parameters or arguments passed to the function: '1 2 3 4 5' Function name: foo The number of positional parameter : 4 All parameters or arguments passed to the function: ‘this is a test‘ |
http://www.cyberciti.biz/faq/unix-linux-bash-function-number-of-arguments-passed/