私のシェルスクリプトは少し錆びているようです。私の望みは、bashのarraylist構成変数をループし、このループの中で得られた必要なパラメーターをすべて呼び出して、すべてをフォークせずに呼び出すことです。bashパラメータの改行による置換
CONFIG="
0, 0x00, 'Reset the chip, enable PLL with P=4, R=1, J=9, D=6338' %
1, 0x01, 'Reset the chip, enable PLL with P=4, R=1, J=9, D=6338' %
51, 0x10, 'Reset the chip, enable PLL with P=4, R=1, J=9, D=6338' %
63, 0xd4, 'Power up and unmute DAC' %
64, 0x00, 'Power up and unmute DAC' %
"
Iだろう、そのパラメータをループするようなので、のように:
基本的に、私は次のように内部のスクリプトの人間が解析可能なコンマ区切りの設定変数と呼ばれなければならないものを作成しました
while read reg val expl; do
printf "%s %s\n" "Calling i2c_write() with reg=${reg//,/}" \
"val=${val//,/} expl=$expl __EOL__";
# i2c_write() call
done <<< "${CONFIG//\%/$'\n'}"
電流出力である:
Calling i2c_write() with reg= val= expl= __EOL__
Calling i2c_write() with reg=0 val=0x00 expl='Reset the chip, enable PLL with P=4, R=1, J=9, D=6338' __EOL__
Calling i2c_write() with reg= val= expl= __EOL__
Calling i2c_write() with reg=1 val=0x01 expl='Reset the chip, enable PLL with P=4, R=1, J=9, D=6338' __EOL__
Calling i2c_write() with reg= val= expl= __EOL__
Calling i2c_write() with reg=51 val=0x10 expl='Reset the chip, enable PLL with P=4, R=1, J=9, D=6338' __EOL__
Calling i2c_write() with reg= val= expl= __EOL__
Calling i2c_write() with reg=63 val=0xd4 expl='Power up and unmute DAC' __EOL__
Calling i2c_write() with reg= val= expl= __EOL__
Calling i2c_write() with reg=64 val=0x00 expl='Power up and unmute DAC' __EOL__
Calling i2c_write() with reg= val= expl= __EOL__
Calling i2c_write() with reg= val= expl= __EOL__
所望の出力は次のようになります
Calling i2c_write() with reg=0 val=0x00 expl='Reset the chip, enable PLL with P=4, R=1, J=9, D=6338' __EOL__
Calling i2c_write() with reg=1 val=0x01 expl='Reset the chip, enable PLL with P=4, R=1, J=9, D=6338' __EOL__
Calling i2c_write() with reg=51 val=0x10 expl='Reset the chip, enable PLL with P=4, R=1, J=9, D=6338' __EOL__
Calling i2c_write() with reg=63 val=0xd4 expl='Power up and unmute DAC' __EOL__
Calling i2c_write() with reg=64 val=0x00 expl='Power up and unmute DAC' __EOL__
私は、より適した構造とCONFIG変数を置き換えることが嬉しい限り:
- a)はフォークが変数のエントリをループに必要ありません、と
- b)人間がこの変数の項目を解析して編集することは比較的簡単です。
- c)bash 3.2.x以上で動作します。
すべての作業ソリューションを読んでたので、私はいつも私の試みはかなり複雑だった感じがしました。私はちょうど適切な解決策を見つけることができませんでした。私はPeter.O、Sorpigal、ormaajに感銘を受けるコメントと美しく作られた自明のコードスニペットに感謝したいと思います。毎日何か新しいものを手に入れることは素晴らしいことです。 – Moreaki