Bash Argument Array nth Element Behavior Specify

Bash: Specifying from nth to nth Element of Argument Array $@

In the Bash programming language (scripting language), this article introduces how to specify from the nth to the nth element of the argument array $@.

Shou Arisaka
1 min read
Nov 1, 2025

In the Bash programming language (scripting language), this article introduces how to specify from the nth to the nth element of the argument array $@.

testf(){
  echo $1 # => hoge
  echo $2 # => fuga
  echo $3 # => foo
  echo "${@:2}" # => fuga foo bar
  echo "${@:2:3}" # => fuga foo bar
  echo "${@:2:1}" # => fuga
}

testf hoge fuga foo bar

shell - Process all arguments except the first one (in a bash script) - Stack Overflow

This way, you can specify any range of the array.

This makes Bash scripting more concise. Please make use of it.

Share this article

Shou Arisaka Nov 1, 2025

๐Ÿ”— Copy Links