回答編集履歴

1

2022/02/16 09:38

投稿

melian
melian

スコア19840

test CHANGED
@@ -1,15 +1,25 @@
1
- `C=("${A[@]}")` とします。
1
+ リファレンス(参照)を使う方法もあります。
2
2
  ```bash
3
+ $ help declare
4
+ :
5
+ Options which set attributes:
6
+ :
7
+ -n make NAME a reference to the variable named by its value
8
+ ```
9
+
10
+ **concat.sh**
11
+ ```bash
3
- A=("L02_M3" "L03_M4")
12
+ A=("L02-M3" "L03-M4")
4
13
  B=("T16" "T16")
5
- C=("${A[@]}")
14
+ declare -n C=A
6
15
 
7
- for ((i=0; i<"${#C[@]}"; i++))
16
+ for ((i=0; i<${#C[@]}; i++))
8
17
  do
9
18
  echo ${C[$i]}–${B[$i]}
10
19
  done
11
20
  ```
12
21
 
22
+ **実行結果**
13
23
  ```bash
14
24
  $ bash concat.sh
15
25
  L02_M3–T16