さて、何か奇妙なことが起こっているようです。history -r
インタラクティブに実行すると、期待どおりに動作します。
$ printf %b '#1401928364\necho\n' > /tmp/hist # Make a test history file with timestamp information.
$ history -r /tmp/hist # Read it into the current history.
$ history 3 # Bash has interpreted the history comment character such that timestamps don't appear on their own line.
220 2014-06-05Thu17:59:55 history -r /tmp/hist # Read it into the current history.
221 2014-06-05Thu00:32:44 echo
222 2014-06-05Thu18:00:07 history 3 # Bash has interpreted the history comment character such that timestamps don't appear on their own line.
ただし、 my から実行すると、.bashrc
期待される動作は異なります。
$ printf %b 'history -r /tmp/hist\nhistory 3\n' > /tmp/bashrc # Make a test bashrc file.
$ bash --rcfile /tmp/bashrc # Run Bash with the test bashrc file; doesn't interpret the history comment character and prints a line containing ‘#1401928364’.
1 #1401928364
2 echo
これは、Freenodeのshbotで確認できます。
17:29:45 <JamesJRH> # printf %b '#1401928364\necho\n' > /tmp/hist; history -r /tmp/hist; history 3
17:29:47 <shbot> 1 printf %b '#1401928364\necho\n' > /tmp/hist; history -r /tmp/hist; history 3
17:29:47 <shbot> 2 echo
17:29:49 <JamesJRH> # printf %b '#1401928364\necho\n' > /tmp/hist; printf %b 'history -r /tmp/hist\nhistory 3\n' > /tmp/bashrc; bash --rcfile /tmp/bashrc
17:29:55 <shbot> 1 #1401928364
17:29:55 <shbot> 2 echo
では、ここで何が起こっているのでしょうか?; .bashrc
ファイルから適切に動作させるにはどうすればよいですか?
アップデート:
私のシェルで:
$ echo "$BASH_VERSION"; printf %b '#1401928364\necho\n' > /tmp/hist; printf %b 'export HISTTIMEFORMAT=\x27%F%a%T \x27\nhistory -r /tmp/hist\nhistory 3\n' > /tmp/bashrc; bash --rcfile /tmp/bashrc
4.2.45(1)-release
1 2014-06-05Thu19:42:31 #1401928364
2 2014-06-05Thu19:42:31 echo
Summary interactive bashrc
without HISTTIMEFORMAT Succeeds. Fails.
with HISTTIMEFORMAT Succeeds. Fails.
shbotの場合:
19:45:29 <JamesJRH> # echo "$BASH_VERSION"; printf %b '#1401928364\necho\n' > /tmp/hist; printf %b 'export HISTTIMEFORMAT=\x27%F%a%T \x27\nhistory -r /tmp/hist\nhistory 3\n' > /tmp/bashrc; bash --rcfile /tmp/bashrc
19:45:36 <shbot> 4.3.18(1)-release
19:45:36 <shbot> 1 2014-06-05Thu00:32:44 echo
19:45:49 <JamesJRH> 42# echo "$BASH_VERSION"; printf %b '#1401928364\necho\n' > /tmp/hist; printf %b 'export HISTTIMEFORMAT=\x27%F%a%T \x27\nhistory -r /tmp/hist\nhistory 3\n' > /tmp/bashrc; bash --rcfile /tmp/bashrc
19:45:56 <shbot> 4.2.47(2)-release
19:45:56 <shbot> 1 2014-06-05Thu00:32:44 echo
19:46:08 <JamesJRH> 41# echo "$BASH_VERSION"; printf %b '#1401928364\necho\n' > /tmp/hist; printf %b 'export HISTTIMEFORMAT=\x27%F%a%T \x27\nhistory -r /tmp/hist\nhistory 3\n' > /tmp/bashrc; bash --rcfile /tmp/bashrc
19:46:15 <shbot> 4.1.11(1)-release
19:46:15 <shbot> 1 2014-06-05Thu00:32:44 echo
Summary interactive bashrc
without HISTTIMEFORMAT Succeeds. Fails.
with HISTTIMEFORMAT Succeeds. Succeeds.
では、私の Bash とshbotのこの違いの原因は何ですか?