bash forward all arguments - How to pass all arguments passed to my bash script to a function of mine?

shell script pass arguments to another script / bash / function / parameter-passing

Let's say I have defined a function abc() that will handle the logic related to analyzing the arguments passed to my script.

How can I pass all arguments my bash script has received to it? The number of params is variable, so I can't just hardcode the arguments passed like this:

abc $1 $2 $3 $4


Answer #1

It's worth mentioning that you can specify argument ranges with this syntax.

function example() {
    echo "line1 ${@:1:1}"; #First argument
    echo "line2 ${@:2:1}"; #Second argument
    echo "line3 ${@:3}"; #Third argument onwards