Skip to content

Instantly share code, notes, and snippets.

@jamband

jamband/hoge.sh

Last active Dec 23, 2015
Embed
What would you like to do?
bash スクリプトの配列操作
#!/bin/bash
declare -a a=(a1 a2 a3)
# 配列をすべて表示
echo "${a[@]}"
# a1 a2 a3
# 配列の先頭に要素を追加
a=(a0 ${a[@]})
echo "${a[@]}"
# a0 a1 a2 a3
# 配列の後尾に要素を追加
a=(${a[@]} a4)
echo "${a[@]}"
# a0 a1 a2 a3 a4
# 配列の先頭の要素を削除
a=(${a[@]:1})
echo "${a[@]}"
# a1 a2 a3 a4
# 配列の後尾の要素を削除
a=(${a[@]:0:$(expr ${#a[@]} - 1)})
echo "${a[@]}"
# a1 a2 a3
# 配列の先頭の要素を表示
echo "${a[0]}"
# a1
# 配列の後尾の要素を表示
echo "${a[$(expr ${#a[@]} - 1)]}"
# a3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.