--init-fileに `history -r`を設定してください。

--init-fileに `history -r`を設定してください。

bashシェルに入ると

touch $HOME/tmp
echo "last thing" >> $HOME/tmp
history -r $HOME/tmp

その後、上矢印をクリックすると「最後」が表示されます。

同じ行をスクリプトに貼り付けてスクリプトをインポートすると、同じ結果が得られます。

しかし、これはうまくいきません。

bash --init-file <(echo "history -r $HOME/tmp")

ベストアンサー1

--init-file${HISTFILE:-$HOME/.bash_history}まず処理してからコンテンツを正常に読み込みます。ファイルに$HISTSIZEアイテムが含まれている場合(通常の場合)、ロードされたアイテムはhistory -r tmp履歴リストの先頭から押されて失われます。

次のバリエーションが私にとって効果的でした(CentOS 4.1.2)。

bash --init-file <(echo history -r temp; echo HISTFILE=/dev/null)
# in new shell history contains only the line(s) from temp

bash --init-file <(echo history -r temp; echo let HISTSIZE+=100)
# in new shell history contains the line(s) from temp THEN .bash_history

おすすめ記事