かべぎわブログ

ブログです

シェルスクリプトで連想配列をつかう

概要

シェルスクリプトで連想配列をつかってみます。

スクリプト

こんなかんじ。
declare -Aで宣言してあげます。

#!/bin/bash

declare -A test_array

test_array['name']='kabegiwa'
test_array['age']=28

echo "name: ${test_array[name]}"
echo "age: ${test_array[age]}"

実行してあげるとこんなかんじ。

$ ./associative_array.sh 
name: kabegiwa
age: 28

おわりに

べんりですね

新しいLinuxの教科書

新しいLinuxの教科書