0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Bashで文字列の構造体を使いたい

0
Posted at

自身の備忘を兼ねて記載を行っています。
「とりあえず動いた」程度のソースなどもございますので参考程度にブラシアップ頂けると幸いです。
また、誤りやもっとよいコーディングやきれいな書き方があるなどご指摘頂けるととてもうれしいです。

今回のお題

任意の件数のデータについて同一の処理を行いたく、構造体で実現しようと思い作成

では、ソースです。

sample01.sh
# ! /bin/bash

# 構造体
LOOP_LISTS=(
	ABCDEFG
	hijklmn
	1234567
	あいうえお
)

i=1
# 構造体の中身をループで一つづつ表示
for LOOP_LIST in ${LOOP_LISTS[@]}; do
	# 同一の処理(今回は表示)
	echo "${i}${LOOP_LIST}"
	let i++
done

# 構造体の中身を指定で表示(1番目のデータは「0」になる)
echo "2番目指定:${LOOP_LISTS[1]}"
実行結果
$ sh sample01.sh
1:ABCDEFG
2:hijklmn
3:1234567
4:あいうえお
2番目指定:hijklmn
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?