What are all the ways you can pass arguments into functions?

Viewed 25

Given function in bash, i looking for more ways to pass arguments to this function.
I knows this way: func ${param1} ${param2} .. .
But I have function without restrict API, and hence, in some places in my code, exists calls to this function in this way: f ${hour} and also in this way f ${day}.
And now I want to pass to this function another argument , exists way to know that in the function?

1 Answers

You can use $# in your function to know how many arguments it received.

Demo:

#!/bin/bash

tata() {
    echo "$#"
}

tata a
tata a b
tata a b c

Output is:

1
2
3
Related