tzselectの最後の行を読む

tzselectの最後の行を読む

タイムゾーンを実用的に設定するために、tzselectの結果をbashスクリプトに読み込もうとします。

コードスニペットは次のとおりです。

/usr/bin/tzselect
#Read last line of tzselect and cp to /etc/localtime
cp /usr/share/zoneinfo/$RESULT /etc/localtime
ntpdate -u 0.centos.pool.ntp.org
hwclock --systohc
#Following lines are just confirmation that the times are the same.
date
hwclock

ベストアンサー1

tzselectstdin/stderrを介してプロンプトを表示し、結果をstdoutに送信します。これは、変数を直接キャプチャできることを意味します。

NEW_TIMEZONE=$(tzselect)
test -n "$NEW_TIMEZONE" && cp -fp /usr/share/zoneinfo/"$NEW_TIMEZONE" /etc/localtime

おすすめ記事