lukmac lukmac - 4 months ago 13
Bash Question

shell scripting: get a specified range of parameters

I normally come here if google doesnt work. So this time it goes like this:
In a function, i want to assign to a variable from the 4-th input parameter onward.
Example:

function foo {
var="$4$5$6..."
use var
commands using $1, etc
}


So i think i cannot use shift, since i want to use $1 afterwards. I do not either want to use an extra var to store $1,$2,$3 and shift. So how should it work?

Answer
function foo {
    var=${@:4}
    # ...
}
Comments