From 15c9133e7be859a7e781d8f6444c8a379c8b572c Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Fri, 28 May 2021 12:39:08 +0900 Subject: [PATCH] history: fix the workaround for bash-3.0 bug of reducing histories --- make_command.sh | 6 ++++++ memo/ChangeLog.md | 1 + note.txt | 24 ++++++++++++++++++++++++ src/history.sh | 4 +--- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/make_command.sh b/make_command.sh index 2feb1a2b..1a1a6298 100755 --- a/make_command.sh +++ b/make_command.sh @@ -361,6 +361,11 @@ function sub:scan/WA-localvar_inherit { grc 'local [^;&|()]*"\$\{[a-zA-Z_0-9]+\[@*\]\}"' } +function sub:scan/mistake-_ble_bash { + echo "--- $FUNCNAME ---" + grc '\(\(.*\b_ble_base\b.*\)\)' +} + function sub:scan { if ! type grc >/dev/null; then echo 'blesh check: grc not found. grc can be found in github.com:akinomyoga/mshex.git/' >&2 @@ -441,6 +446,7 @@ function sub:scan { g' sub:scan/eval-literal sub:scan/WA-localvar_inherit + sub:scan/mistake-_ble_bash sub:scan/memo-numbering } diff --git a/memo/ChangeLog.md b/memo/ChangeLog.md index fcd77ae3..fc4eb836 100644 --- a/memo/ChangeLog.md +++ b/memo/ChangeLog.md @@ -122,6 +122,7 @@ - util: work around bash-3.0 bug `"${scal[@]/xxx}"` `#D1570` 0000000 - sabbrev (`ble-sabbrev`): fix delayed output before the initialization `#D1573` 0000000 - main: fix the workaround for `set -u` `#D1575` 0000000 +- history: fix the workaround for bash-3.0 bug of reducing histories `#D1576` 0000000 ## Compatibility diff --git a/note.txt b/note.txt index c0f92bb1..dc9c40cc 100644 --- a/note.txt +++ b/note.txt @@ -4655,6 +4655,30 @@ bash_tips 2021-05-28 + * history: bash-3.0 で履歴の数が減少していく問題が再発している [#D1576] + + これは対策をした筈なのに何故だろうか。 + + 取り敢えず対策コードにちゃんと進入しているのかどうかだけでも確認する。 + + 再現条件が分かった。bashrc からロードしていると発生しないが、コマンドから + source して attach すると発生する。bash-3.1 では再現しない。 + + 該当箇所で確認したがちゃんと復元できている様な気がする。history -p で検索し + てみたらもう一箇所別の場所で呼び出している。其処の判定条件を確認すると + bash-4.0 未満の場合には無条件でサブシェルで実行している様に見える。と思った + がよく見たら _ble_bash となるべき所が _ble_base になってしまっている。 + + 然し、そもそもサブシェルの判定は ((BASH_SUBSHELL)) で判定できるのでこんなに + 複雑な式を用いる必要はない。 + + * done: 算術式の中で誤って _ble_base を使ってしまうという事が余りに多いので + これも make_command.sh に登録しておくのが良い気がする。登録した。 + + $ grc '\(\(.*\b_ble_base\b.*\)\)' + + 他には同じミスをしている箇所は存在しなかった様である。 + * main: set -u で壊れていないか久しぶりに確認する必要がある気がする [#D1575] 試してみたら沢山のエラーが発生している。というか本来 set +u で待避している diff --git a/src/history.sh b/src/history.sh index aaca50ce..5f47c62b 100644 --- a/src/history.sh +++ b/src/history.sh @@ -37,9 +37,7 @@ function ble/builtin/history/is-empty { # Note: 状況によって history -p で項目が減少するので # サブシェルの中で評価する必要がある。 # 但し、サブシェルの中に既にいる時にはこの fork は省略できる。 - # Bash 3.2 以前ではサブシェルの中にいるかどうかの判定自体に - # fork&exec が必要になるので常にサブシェルで評価する。 - if ((_ble_base<40000)) || [[ $BASHPID == "$$" ]]; then + if ((!BASH_SUBSHELL)); then (! builtin history -p '!!') else ! builtin history -p '!!'