Bash – What does this ${@:2} mean in shell scripting

bashkshshell-script

I see this in a shell script.

variable=${@:2}

What is it doing?

Best Answer

It's showing the contents of the special variable $@, in Bash. It contains all the command line arguments, and this command is taking all the arguments from the second one on and storing them in a variable, variable.

Example

Here's an exampe script.

#!/bin/bash

echo ${@:2}

variable=${@:3}
echo $variable

Example run:

./ex.bash 1 2 3 4 5
2 3 4 5
3 4 5

References

Related Question