0
0

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 3 years have passed since last update.

[fish-shell] [05] 多次元配列もどきを実装する

Last updated at Posted at 2021-09-18

概要

「:」を区切りにした 3次元配列もどきの実装例である.
fish-shell V2.7.1 で動作確認済み.

#!/usr/bin/env fish
#
# 3次元配列もどき の実装例
#

# D3ARAY (3次元配列もどき) を定義する. セパレータは「:」とする.
# そのため、値には「:」を使用しないという制約が必要になる.
set -l    D3ARY    '
  "A"  : "aa" : "1>/tmp/A" 
  "B"  : "bb" : "1>/tmp/B" 
  "C"  : "cc" : "1>/tmp/C" 
'

# D3ARAY (3次元配列もどき) を変数 FLD に格納する
set -l  FLD ( string trim $D3ARY )
set -l  F1
set -l  F2
set -l  F3

# D3ARAY (3次元配列もどき) を一行ずつ取り出す
for i in (seq 1 (count $FLD) )
  # 「:」区切りで各フィールドを取り出している
  set F1 ( string trim (echo $FLD[$i] | cut -d':' -f1) )
  set F2 ( string trim (echo $FLD[$i] | cut -d':' -f2) )
  set F3 ( string trim (echo $FLD[$i] | cut -d':' -f3) )
  echo "--------------------------------------------"
  echo "F1: $F1"
  echo "F2: $F2"
  echo "F3: $F3"
end

実行結果

--------------------------------------------
F1: "A"
F2: "aa"
F3: "1>/tmp/A"
--------------------------------------------
F1: "B"
F2: "bb"
F3: "1>/tmp/B"
--------------------------------------------
F1: "C"
F2: "cc"
F3: "1>/tmp/C"

以上.

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?