Test script:
#!/bin/bash
var=$1
function test {
echo "dollar1 $1"
echo "var $var"
}
test
exit
output
./test.sh d
dollar1
var d
Why isn't $1 populated inside the function, and is there a way to pass $1...$n to all functions without having them defined as a variable separately?
The function has its own arguments. You can pass all arguments to a function using "$@", which expands to all the positional parameters in order:
test "$@"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With