これはコマンドラインでは機能しますが、スクリプトでは機能しません。
read -r local_temperature system_mode preset running_state current_heating_setpoi
nt <<< $(thermostat)
構文エラー:予期しないリダイレクト
スクリプトでできますか? 5回くらい使うとcut
ちょっと良くないようですが、思い出すのはそれだけですね。
ベストアンサー1
<<
ダッシュ(Ubuntuの場合)では、herestringの代わりに既存のheredoc()を使用できます。
read -r local_temperature system_mode ... <<END # END must be unquoted
$(thermostat)
END
ただし、busyboxを使用すると、可変ゴミとして見える偽の「見つかりません」エラーが発生します。
(1)コマンドの出力にglob文字が含まれていない場合、またはglobまたは同様のコマンドを使用してglobをオフにし、set -f
(2)後続のコマンドに必要な引数を渡さずにスクリプトを実行する場合は、次のことができます。 (ab) 位置引数を使用します。
set -- $(thermostat); local_temperature=$1; system_mode=$2; ...
これは、「最後= n番目のvarに結合されたn-1以降のすべての単語」とは異なりますが、read
次の方法を使用しておおよその計算ができます。
a=$1; b=$2; c=$3; shift 3; d=$*
# d gets all words after the first 3 but not the original delimiters e.g. multiple spaces