シェルが行を解析しているとき、それは行を単語にトークン化し、単語に対してさまざまな展開を(順番に)実行してから、コマンドを実行します。
と思います test=1:2:3:4:5:6
このコマンドを見てみましょう: IFS=":" read a b c d e f <<< "$test"
トークン化後、パラメーターの展開が行われます。IFS=":"
read
a
b
c
d
e
f
<<<
"1:2:3:4:5:6"
シェルは、readコマンドの実行中にIFS変数を設定し、read
$ IFSをそのinputに適用する方法を知っており、変数名に値を与えます。
このコマンドのストーリーは似ていますが、結果は異なります。 HOME="hello" echo "$HOME"
コマンドの開始前にパラメーターの展開が行われるため、シェルには次の機能があります。
HOME="hello" echo "/home/username"
そして、echoコマンドの実行中、$ HOMEの新しい値はまったく使用されません。
あなたがやろうとしていることを達成するために、
# Delay expansion of the variable until its new value is set
HOME="hello" eval 'echo "$HOME"'
または
# Using a subshell, so the altered env variable does not affect the parent.
# The semicolon means that the variable assignment will occur before
# the variable expansion
(HOME="hello"; echo "$HOME")
ただし、最初のものは選択しないでください。
local
です。