From e87f923438a8eb83dc2274abddbbc0ed1dcc4c49 Mon Sep 17 00:00:00 2001 From: sabi789 Date: Tue, 5 May 2026 11:27:30 -0400 Subject: [PATCH 1/4] Add _ENCODE_FILE_NEW and _ENCODE_FILE_EXISTING variables Signed-off-by: sabi789 --- stable-patches/variable.patch | 58 ++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/stable-patches/variable.patch b/stable-patches/variable.patch index 958037c..523a835 100644 --- a/stable-patches/variable.patch +++ b/stable-patches/variable.patch @@ -13,17 +13,19 @@ index 4e6f93b..a37e258 100644 #include #include "chartypes.h" #if defined (HAVE_PWD_H) -@@ -5757,6 +5761,9 @@ struct name_and_function { +@@ -5757,6 +5761,11 @@ struct name_and_function { }; static struct name_and_function special_vars[] = { +#if defined (__MVS__) + { "_BPXK_AUTOCVT", sv_bpxk_autocvt }, ++ { "_ENCODE_FILE_NEW", sv_encode_file_new }, ++ { "_ENCODE_FILE_EXISTING", sv_encode_file_existing }, +#endif { "BASH_COMPAT", sv_shcompat }, { "BASH_XTRACEFD", sv_xtracefd }, -@@ -5978,6 +5985,32 @@ sv_globsort (const char *name) +@@ -5978,6 +5987,76 @@ sv_globsort (const char *name) setup_globsort (name); } @@ -51,6 +53,52 @@ index 4e6f93b..a37e258 100644 + else if (strcmp(value, "OFF") == 0) + __ae_autoconvert_state(_CVTSTATE_OFF); +} ++ ++/* What to do when _ENCODE_FILE_NEW changes. */ ++void ++sv_encode_file_new (const char *name) ++{ ++ SHELL_VAR *v; ++ char *value; ++ ++ v = find_variable (name); ++ if (v == 0 || value_cell (v) == 0) ++ { ++ /* Unset the environment variable to use system default */ ++ unsetenv("_ENCODE_FILE_NEW"); ++ return; ++ } ++ ++ value = value_cell (v); ++ /* Set the environment variable for child processes and file operations */ ++ if (setenv("_ENCODE_FILE_NEW", value, 1) != 0) ++ { ++ internal_warning ("Failed to set _ENCODE_FILE_NEW environment variable"); ++ } ++} ++ ++/* What to do when _ENCODE_FILE_EXISTING changes. */ ++void ++sv_encode_file_existing (const char *name) ++{ ++ SHELL_VAR *v; ++ char *value; ++ ++ v = find_variable (name); ++ if (v == 0 || value_cell (v) == 0) ++ { ++ /* Unset the environment variable to use system default */ ++ unsetenv("_ENCODE_FILE_EXISTING"); ++ return; ++ } ++ ++ value = value_cell (v); ++ /* Set the environment variable for child processes and file operations */ ++ if (setenv("_ENCODE_FILE_EXISTING", value, 1) != 0) ++ { ++ internal_warning ("Failed to set _ENCODE_FILE_EXISTING environment variable"); ++ } ++} +#endif + #if defined (READLINE) @@ -60,14 +108,16 @@ diff --git i/variables.h w/variables.h index e939e59..719d5ac 100644 --- i/variables.h +++ w/variables.h -@@ -454,6 +454,10 @@ extern void sv_xtracefd (const char *); +@@ -454,6 +454,11 @@ extern void sv_xtracefd (const char *); extern void sv_shcompat (const char *); extern void sv_globsort (const char *); +#if defined (__MVS__) +extern void sv_bpxk_autocvt (const char *); ++extern void sv_encode_file_new (const char *); ++extern void sv_encode_file_existing (const char *); +#endif + #if defined (READLINE) extern void sv_comp_wordbreaks (const char *); - extern void sv_terminal (const char *); + extern void sv_terminal (const char *); \ No newline at end of file From 58e385de1c1b7c46525d7de7c99709942c6c4583 Mon Sep 17 00:00:00 2001 From: sabi789 Date: Wed, 6 May 2026 06:03:25 -0400 Subject: [PATCH 2/4] Rework of patch Signed-off-by: sabi789 --- stable-patches/variable.patch | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/stable-patches/variable.patch b/stable-patches/variable.patch index 523a835..d174b27 100644 --- a/stable-patches/variable.patch +++ b/stable-patches/variable.patch @@ -1,7 +1,7 @@ -diff --git i/variables.c w/variables.c -index 4e6f93b..a37e258 100644 ---- i/variables.c -+++ w/variables.c +diff --git a/variables.c b/variables.c +index 4e6f93b..77193b7 100644 +--- a/variables.c ++++ b/variables.c @@ -36,6 +36,10 @@ # include #endif @@ -25,7 +25,7 @@ index 4e6f93b..a37e258 100644 { "BASH_COMPAT", sv_shcompat }, { "BASH_XTRACEFD", sv_xtracefd }, -@@ -5978,6 +5987,76 @@ sv_globsort (const char *name) +@@ -5978,6 +5987,78 @@ sv_globsort (const char *name) setup_globsort (name); } @@ -104,11 +104,11 @@ index 4e6f93b..a37e258 100644 #if defined (READLINE) void sv_comp_wordbreaks (const char *name) -diff --git i/variables.h w/variables.h -index e939e59..719d5ac 100644 ---- i/variables.h -+++ w/variables.h -@@ -454,6 +454,11 @@ extern void sv_xtracefd (const char *); +diff --git a/variables.h b/variables.h +index e939e59..304ed3f 100644 +--- a/variables.h ++++ b/variables.h +@@ -454,6 +454,12 @@ extern void sv_xtracefd (const char *); extern void sv_shcompat (const char *); extern void sv_globsort (const char *); @@ -120,4 +120,4 @@ index e939e59..719d5ac 100644 + #if defined (READLINE) extern void sv_comp_wordbreaks (const char *); - extern void sv_terminal (const char *); \ No newline at end of file + extern void sv_terminal (const char *); From e240ba18d721a9733cf15348a978beec1b046a95 Mon Sep 17 00:00:00 2001 From: sabi789 Date: Wed, 6 May 2026 07:33:13 -0400 Subject: [PATCH 3/4] Augmentatcode Issue fix Signed-off-by: sabi789 --- stable-patches/variable.patch | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/stable-patches/variable.patch b/stable-patches/variable.patch index d174b27..b986746 100644 --- a/stable-patches/variable.patch +++ b/stable-patches/variable.patch @@ -1,5 +1,5 @@ diff --git a/variables.c b/variables.c -index 4e6f93b..77193b7 100644 +index 4e6f93b..5bf5db5 100644 --- a/variables.c +++ b/variables.c @@ -36,6 +36,10 @@ @@ -25,7 +25,7 @@ index 4e6f93b..77193b7 100644 { "BASH_COMPAT", sv_shcompat }, { "BASH_XTRACEFD", sv_xtracefd }, -@@ -5978,6 +5987,78 @@ sv_globsort (const char *name) +@@ -5978,6 +5987,76 @@ sv_globsort (const char *name) setup_globsort (name); } @@ -64,17 +64,16 @@ index 4e6f93b..77193b7 100644 + v = find_variable (name); + if (v == 0 || value_cell (v) == 0) + { -+ /* Unset the environment variable to use system default */ -+ unsetenv("_ENCODE_FILE_NEW"); ++ /* Unbind the variable using Bash's internal function */ ++ unbind_variable("_ENCODE_FILE_NEW"); + return; + } + + value = value_cell (v); -+ /* Set the environment variable for child processes and file operations */ -+ if (setenv("_ENCODE_FILE_NEW", value, 1) != 0) -+ { -+ internal_warning ("Failed to set _ENCODE_FILE_NEW environment variable"); -+ } ++ /* Use Bash's bind_variable with export flag */ ++ v = bind_variable("_ENCODE_FILE_NEW", value, 0); ++ if (v) ++ VSETATTR(v, att_exported); +} + +/* What to do when _ENCODE_FILE_EXISTING changes. */ @@ -87,17 +86,16 @@ index 4e6f93b..77193b7 100644 + v = find_variable (name); + if (v == 0 || value_cell (v) == 0) + { -+ /* Unset the environment variable to use system default */ -+ unsetenv("_ENCODE_FILE_EXISTING"); ++ /* Unbind the variable using Bash's internal function */ ++ unbind_variable("_ENCODE_FILE_EXISTING"); + return; + } + + value = value_cell (v); -+ /* Set the environment variable for child processes and file operations */ -+ if (setenv("_ENCODE_FILE_EXISTING", value, 1) != 0) -+ { -+ internal_warning ("Failed to set _ENCODE_FILE_EXISTING environment variable"); -+ } ++ /* Use Bash's bind_variable with export flag */ ++ v = bind_variable("_ENCODE_FILE_EXISTING", value, 0); ++ if (v) ++ VSETATTR(v, att_exported); +} +#endif + From 50ac0584a6ff87cebdf894f28ecf6b5a81d6d69c Mon Sep 17 00:00:00 2001 From: sabi789 Date: Thu, 7 May 2026 04:17:52 -0400 Subject: [PATCH 4/4] Add Testcase for _ENCODE_FILE_NEW and _ENCODE_FILE_EXISTING Signed-off-by: sabi789 --- stable-patches/MANIFEST.patch | 7 +- .../tests/encodefilevars.right.patch | 48 ++++++++++ .../tests/encodefilevars.tests.patch | 95 +++++++++++++++++++ stable-patches/tests/run-encodefilevars.patch | 8 ++ 4 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 stable-patches/tests/encodefilevars.right.patch create mode 100644 stable-patches/tests/encodefilevars.tests.patch create mode 100644 stable-patches/tests/run-encodefilevars.patch diff --git a/stable-patches/MANIFEST.patch b/stable-patches/MANIFEST.patch index 5d30b8c..41398b5 100644 --- a/stable-patches/MANIFEST.patch +++ b/stable-patches/MANIFEST.patch @@ -2,19 +2,22 @@ diff --git a/MANIFEST b/MANIFEST index 985d179..2a1cd25 100644 --- a/MANIFEST +++ b/MANIFEST -@@ -1455,6 +1455,8 @@ tests/quotearray2.sub f +@@ -1455,6 +1455,10 @@ tests/quotearray2.sub f tests/quotearray3.sub f tests/quotearray4.sub f tests/quotearray5.sub f ++tests/encodefilevars.tests f ++tests/encodefilevars.right f +tests/rbash.tests f +tests/rbash.right f tests/read.tests f tests/read.right f tests/read1.sub f -@@ -1565,6 +1567,7 @@ tests/run-printf f +@@ -1565,6 +1569,8 @@ tests/run-printf f tests/run-procsub f tests/run-quote f tests/run-quotearray f ++tests/run-encodefilevars f +tests/run-rbash f tests/run-read f tests/run-redir f diff --git a/stable-patches/tests/encodefilevars.right.patch b/stable-patches/tests/encodefilevars.right.patch new file mode 100644 index 0000000..2b068e7 --- /dev/null +++ b/stable-patches/tests/encodefilevars.right.patch @@ -0,0 +1,48 @@ +diff --git a/tests/encodefilevars.right b/tests/encodefilevars.right +new file mode 100644 +index 0000000..0c442f0 +--- /dev/null ++++ b/tests/encodefilevars.right +@@ -0,0 +1,42 @@ ++Testing _ENCODE_FILE_NEW and _ENCODE_FILE_EXISTING variable handling ++Test 1: Setting _ENCODE_FILE_NEW to UTF-8 ++_ENCODE_FILE_NEW=UTF-8 ++UTF-8 ++Test 2: Setting _ENCODE_FILE_EXISTING to ISO8859-1 ++_ENCODE_FILE_EXISTING=ISO8859-1 ++ISO8859-1 ++Test 3: Changing _ENCODE_FILE_NEW to IBM-1047 ++_ENCODE_FILE_NEW=IBM-1047 ++IBM-1047 ++Test 4: Changing _ENCODE_FILE_EXISTING to UTF-8 ++_ENCODE_FILE_EXISTING=UTF-8 ++UTF-8 ++Test 5: Unsetting _ENCODE_FILE_NEW ++_ENCODE_FILE_NEW= ++_ENCODE_FILE_NEW is not set in environment ++Test 6: Unsetting _ENCODE_FILE_EXISTING ++_ENCODE_FILE_EXISTING= ++_ENCODE_FILE_EXISTING is not set in environment ++Test 7: Setting both variables together ++_ENCODE_FILE_NEW=UTF-8 ++_ENCODE_FILE_EXISTING=ISO8859-1 ++UTF-8 ++ISO8859-1 ++Test 8: Verify variables are exported to subshell ++Subshell _ENCODE_FILE_NEW=UTF-8 ++Subshell _ENCODE_FILE_EXISTING=IBM-1047 ++Test 9: Setting empty value for _ENCODE_FILE_NEW ++_ENCODE_FILE_NEW= ++_ENCODE_FILE_NEW is not set in environment ++Test 10: Setting empty value for _ENCODE_FILE_EXISTING ++_ENCODE_FILE_EXISTING= ++_ENCODE_FILE_EXISTING is not set in environment ++Test 11: Multiple set/unset cycles ++Set 1: _ENCODE_FILE_NEW=UTF-8 ++Unset 1: _ENCODE_FILE_NEW= ++Set 2: _ENCODE_FILE_NEW=ISO8859-1 ++Unset 2: _ENCODE_FILE_NEW= ++Test 12: Verify variable attributes ++declare -x _ENCODE_FILE_NEW="UTF-8" ++declare -x _ENCODE_FILE_EXISTING="IBM-1047" ++Tests completed diff --git a/stable-patches/tests/encodefilevars.tests.patch b/stable-patches/tests/encodefilevars.tests.patch new file mode 100644 index 0000000..44b74ef --- /dev/null +++ b/stable-patches/tests/encodefilevars.tests.patch @@ -0,0 +1,95 @@ +diff --git a/tests/encodefilevars.tests b/tests/encodefilevars.tests +new file mode 100644 +index 0000000..0000000 +--- /dev/null ++++ b/tests/encodefilevars.tests +@@ -0,0 +1,89 @@ ++# Test _ENCODE_FILE_NEW and _ENCODE_FILE_EXISTING environment variable handling ++# These tests verify that bash properly manages z/OS file encoding variables ++ ++echo "Testing _ENCODE_FILE_NEW and _ENCODE_FILE_EXISTING variable handling" ++ ++# Test 1: Setting _ENCODE_FILE_NEW ++echo "Test 1: Setting _ENCODE_FILE_NEW to UTF-8" ++export _ENCODE_FILE_NEW=UTF-8 ++echo "_ENCODE_FILE_NEW=${_ENCODE_FILE_NEW}" ++printenv _ENCODE_FILE_NEW ++ ++# Test 2: Setting _ENCODE_FILE_EXISTING ++echo "Test 2: Setting _ENCODE_FILE_EXISTING to ISO8859-1" ++export _ENCODE_FILE_EXISTING=ISO8859-1 ++echo "_ENCODE_FILE_EXISTING=${_ENCODE_FILE_EXISTING}" ++printenv _ENCODE_FILE_EXISTING ++ ++# Test 3: Changing _ENCODE_FILE_NEW value ++echo "Test 3: Changing _ENCODE_FILE_NEW to IBM-1047" ++export _ENCODE_FILE_NEW=IBM-1047 ++echo "_ENCODE_FILE_NEW=${_ENCODE_FILE_NEW}" ++printenv _ENCODE_FILE_NEW ++ ++# Test 4: Changing _ENCODE_FILE_EXISTING value ++echo "Test 4: Changing _ENCODE_FILE_EXISTING to UTF-8" ++export _ENCODE_FILE_EXISTING=UTF-8 ++echo "_ENCODE_FILE_EXISTING=${_ENCODE_FILE_EXISTING}" ++printenv _ENCODE_FILE_EXISTING ++ ++# Test 5: Unsetting _ENCODE_FILE_NEW ++echo "Test 5: Unsetting _ENCODE_FILE_NEW" ++unset _ENCODE_FILE_NEW ++echo "_ENCODE_FILE_NEW=${_ENCODE_FILE_NEW}" ++printenv _ENCODE_FILE_NEW || echo "_ENCODE_FILE_NEW is not set in environment" ++ ++# Test 6: Unsetting _ENCODE_FILE_EXISTING ++echo "Test 6: Unsetting _ENCODE_FILE_EXISTING" ++unset _ENCODE_FILE_EXISTING ++echo "_ENCODE_FILE_EXISTING=${_ENCODE_FILE_EXISTING}" ++printenv _ENCODE_FILE_EXISTING || echo "_ENCODE_FILE_EXISTING is not set in environment" ++ ++# Test 7: Setting both variables together ++echo "Test 7: Setting both variables together" ++export _ENCODE_FILE_NEW=UTF-8 _ENCODE_FILE_EXISTING=ISO8859-1 ++echo "_ENCODE_FILE_NEW=${_ENCODE_FILE_NEW}" ++echo "_ENCODE_FILE_EXISTING=${_ENCODE_FILE_EXISTING}" ++printenv _ENCODE_FILE_NEW ++printenv _ENCODE_FILE_EXISTING ++ ++# Test 8: Verify variables are exported to subshell ++echo "Test 8: Verify variables are exported to subshell" ++export _ENCODE_FILE_NEW=UTF-8 ++export _ENCODE_FILE_EXISTING=IBM-1047 ++${THIS_SH} -c 'echo "Subshell _ENCODE_FILE_NEW=${_ENCODE_FILE_NEW}"; echo "Subshell _ENCODE_FILE_EXISTING=${_ENCODE_FILE_EXISTING}"' ++ ++# Test 9: Setting empty value ++echo "Test 9: Setting empty value for _ENCODE_FILE_NEW" ++export _ENCODE_FILE_NEW= ++echo "_ENCODE_FILE_NEW=${_ENCODE_FILE_NEW}" ++printenv _ENCODE_FILE_NEW || echo "_ENCODE_FILE_NEW is not set in environment" ++ ++# Test 10: Setting empty value for _ENCODE_FILE_EXISTING ++echo "Test 10: Setting empty value for _ENCODE_FILE_EXISTING" ++export _ENCODE_FILE_EXISTING= ++echo "_ENCODE_FILE_EXISTING=${_ENCODE_FILE_EXISTING}" ++printenv _ENCODE_FILE_EXISTING || echo "_ENCODE_FILE_EXISTING is not set in environment" ++ ++# Test 11: Multiple set/unset cycles ++echo "Test 11: Multiple set/unset cycles" ++export _ENCODE_FILE_NEW=UTF-8 ++echo "Set 1: _ENCODE_FILE_NEW=${_ENCODE_FILE_NEW}" ++unset _ENCODE_FILE_NEW ++echo "Unset 1: _ENCODE_FILE_NEW=${_ENCODE_FILE_NEW}" ++export _ENCODE_FILE_NEW=ISO8859-1 ++echo "Set 2: _ENCODE_FILE_NEW=${_ENCODE_FILE_NEW}" ++unset _ENCODE_FILE_NEW ++echo "Unset 2: _ENCODE_FILE_NEW=${_ENCODE_FILE_NEW}" ++ ++# Test 12: Verify variable attributes ++echo "Test 12: Verify variable attributes" ++export _ENCODE_FILE_NEW=UTF-8 ++export _ENCODE_FILE_EXISTING=IBM-1047 ++declare -p _ENCODE_FILE_NEW 2>/dev/null || echo "_ENCODE_FILE_NEW variable info not available" ++declare -p _ENCODE_FILE_EXISTING 2>/dev/null || echo "_ENCODE_FILE_EXISTING variable info not available" ++ ++# Cleanup ++unset _ENCODE_FILE_NEW ++unset _ENCODE_FILE_EXISTING ++echo "Tests completed" diff --git a/stable-patches/tests/run-encodefilevars.patch b/stable-patches/tests/run-encodefilevars.patch new file mode 100644 index 0000000..3a0a849 --- /dev/null +++ b/stable-patches/tests/run-encodefilevars.patch @@ -0,0 +1,8 @@ +diff --git a/tests/run-encodefilevars b/tests/run-encodefilevars +new file mode 100644 +index 0000000..0000000 +--- /dev/null ++++ b/tests/run-encodefilevars +@@ -0,0 +1,2 @@ ++${THIS_SH} ./encodefilevars.tests > ${BASH_TSTOUT} 2>&1 ++diff ${BASH_TSTOUT} encodefilevars.right | tee encodefilevars.output && rm -f ${BASH_TSTOUT}