diff --git a/ble.pp b/ble.pp index 03e16d81..9853f3a1 100644 --- a/ble.pp +++ b/ble.pp @@ -284,11 +284,15 @@ function ble/base/is-POSIXLY_CORRECT { _ble_bash_builtins_adjusted= _ble_bash_builtins_save= } 2>/dev/null # set -x 対策 +## @fn ble/base/adjust-builtin-wrappers/.assign +## @remarks This function may be called with POSIXLY_CORRECT=y function ble/base/adjust-builtin-wrappers/.assign { if [[ ${_ble_util_assign_base-} ]]; then local _ble_local_tmpfile; ble/util/assign/.mktmp builtin eval -- "$1" >| "$_ble_local_tmpfile" - IFS= ble/bash/read -d '' defs < "$_ble_local_tmpfile" + local IFS= + ble/bash/read -d '' defs < "$_ble_local_tmpfile" + IFS=$_ble_term_IFS ble/util/assign/.rmtmp else defs=$(builtin eval -- "$1") diff --git a/docs/ChangeLog.md b/docs/ChangeLog.md index c1781aee..04ce0256 100644 --- a/docs/ChangeLog.md +++ b/docs/ChangeLog.md @@ -503,6 +503,7 @@ - term (`terminology`): work around terminal glitches `#D1946` 9a1b4f9 - main (`ble/bin/awk`): add workaround for macOS `awk-32` `#D1974` e2ec89c - util.hook: workaround bash-5.2 bug of nested read by `WINCH` `#D1981` a5b10e8 + - main (`ble/base/adjust-builtin-wrappers`): fix persistent tempenv `IFS=` in bash-5.0 (reported by pt12lol) `#D2030` xxxxxxxx - edit: always adjust the terminal states with `bind -x` (reported by linwaytin) `#D1983` 5d14cf1 - edit: restore `PS1` while processing `bind -x` (reported by adoyle-h) `#D2024` 2eadcd5b - syntax: suppress brace expansions in designated array initialization in Bash 5.3 `#D1989` 1e7b884 diff --git a/note.txt b/note.txt index 6a49041c..afb69396 100644 --- a/note.txt +++ b/note.txt @@ -6724,6 +6724,34 @@ bash_tips Done (実装ログ) ------------------------------------------------------------------------------- +2023-04-03 + + * main (adjust-builtin-wrappers): IFS= が設定されてしまう @ bash-5.0 (reported by pt12lol) [#D2030] + https://github.com/akinomyoga/ble.sh/issues/311 + + POSIXLY_CORRECT=y の環境で IFS= ble/bash/read を実行していた為に IFS= が関 + 数呼び出し後も残る様になってしまったのだった。 + + ? 然し不思議なのは何故か bash-5.0 だけで振る舞いが再現するという事。 + bash-5.1 以降は関数呼び出しの変数代入は posix であっても環境に残らない様 + になっているのは良い。然し、bash-4.4 以前については bash-5.0 と同様に環境 + に tempenv が残る様に見える。何故この時にだけ問題がないのだろうか。或いは、 + 何処か別のレベルで local IFS が設定されているという事か、或いは呼び出し元 + の local POSIXLY_CORRECT=y は影響を与えないという事なのだろうか。よく分か + らないが取り敢えずは問題は封じた筈なので気にしない事にする。 + + 取り敢えず関数呼び出しの前に変数代入を置かない様にする。明らかに ble.sh の + 内部だけで使われる関数については気にしなくて良い。util.sh の一般のライブラ + リ関数についてはちゃんと posix を避ける様にする事にする。 + + ? これよりも前には問題にならなかったのかというのが疑問である→どうも試して + みた所 read や builtin read では tempenv は posix モードであったとしても + 環境には残らない様である。つまり、本当にシェル関数特有の振る舞いだったと + いう事である。 + + builtin read から ble/bash/read に置き換えられたのが a5b10e8b である。こ + れは #D1981 に関係している。 + 2023-04-02 * bgproc: bash-4.2 での bgproc#start で {bgproc[0]} は存在しないというエラーメッセージ [#D2029] diff --git a/src/util.sh b/src/util.sh index e3d306b9..8c55b4ed 100644 --- a/src/util.sh +++ b/src/util.sh @@ -1656,7 +1656,8 @@ if ((_ble_bash>=40000)); then else function ble/util/readfile { # 465ms for man bash [[ -r $2 && ! -d $2 ]] || return 1 - IFS= ble/bash/read -d '' "$1" < "$2" + local IFS= + ble/bash/read -d '' "$1" < "$2" return 0 } function ble/util/mapfile { @@ -2216,8 +2217,8 @@ else function ble/util/assign { local _ble_local_tmpfile; ble/util/assign/.mktmp builtin eval -- "$2" >| "$_ble_local_tmpfile" - local _ble_local_ret=$? - IFS= ble/bash/read -d '' "$1" < "$_ble_local_tmpfile" + local _ble_local_ret=$? IFS= + ble/bash/read -d '' "$1" < "$_ble_local_tmpfile" ble/util/assign/.rmtmp builtin eval "$1=\${$1%\$_ble_term_nl}" return "$_ble_local_ret" @@ -6666,9 +6667,11 @@ else local bytes byte ble/util/assign bytes ' - while IFS= ble/bash/read -n 1 byte; do + local IFS= + while ble/bash/read -n 1 byte; do builtin printf "%d " "'\''$byte" done <<< "$s" + IFS=$_ble_term_IFS ' "ble/encoding:$bleopt_input_encoding/b2c" $bytes }