Last active
December 23, 2015 14:19
-
-
Save jamband/6647582 to your computer and use it in GitHub Desktop.
bash スクリプトの配列操作
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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