On Mon, Jun 22, 2026 at 05:55:49PM +0200, Patrice Dumas wrote:
> Hello,
> 
> The tta/maintain/regenerate_cmd_tests.sh script generates
> tta/tests/Makefile.onetst, which is included in tta/tests/Makefile.am.
> There is a while loop reading from a file, with a redirection, in which a
> global variable, $type_test_files is changed.  The relevant code,
> simplified, is like:
> 
> type_test_files=
> 
>     ...
>     while read line ; do
>       ...
>       name_prepended=...
>       name=...
>       one_test_file="test_scripts/${name_prepended}perl_$name.sh"
>       type_test_files="$type_test_files $one_test_file"
>       ...
>     done < $driving_file
>     ...
> 
> This script is called from autogen.sh, and in Solaris 10, the result is
> incorrect, which seems to be a known issue of Solaris /bin/sh (before
> Solaris 11), in which a subshell is started for while even without pipe:
> 
>  
> https://unix.stackexchange.com/questions/137680/variable-scope-in-while-read-loop-on-solaris
> 
> tta/maintain/regenerate_cmd_tests.sh is also called from 
> tta/tests/Makefile.am,
> but in that case $SHELL is used, which is found by configure and is
> another shell that /bin/sh, so the issue does not materialize in that
> case.
> 
> I see two ways to solve this issue
> 
> 1) use a trick to get the code above to work on Solaris 10 /bin/sh.  I
>   have no idea how to do that, do not hesitate if you have an idea

I read that no options to "read" are portable, which is a shame as "read -u FD"
would have been useful here.

One idea is to reassign standard input:

diff --git a/tta/maintain/regenerate_cmd_tests.sh 
b/tta/maintain/regenerate_cmd_tests.sh
index 8249175cc2..e99804393f 100755
--- a/tta/maintain/regenerate_cmd_tests.sh
+++ b/tta/maintain/regenerate_cmd_tests.sh
@@ -83,6 +83,7 @@ for test_dir in $test_dirs; do
     else
       language_option="-${language_type}"
     fi
+    exec < $driving_file
     while read line ; do
       if echo $line | grep '^ *#' >/dev/null; then continue; fi
       name=`echo $line | awk '{print $1}'`
@@ -136,7 +137,7 @@ cat $dir/$one_test_logs_dir/'"${language_type}"'_$name.log
 exit $exit_status
 ' >> $one_test_file
       chmod 0755 $one_test_file
-    done < $driving_file
+    done
   else
     echo "$0: Missing file $driving_file" 1>&2
     exit 1

This seems to work fine.

I saw that one of the posts on that Stack Exchange link did something similar,
with the complication of saving the original standard input.



> 
> 2) the call in tta/tests/Makefile.am depends on the script itself, so
>   another possibility is to create an empty file in autogen.sh, with a
>   date in the past, which makes sure that tta/maintain/regenerate_cmd_tests.sh
>   is invoked from tta/tests/Makefile.am.
> 
> Something like:
> 
> cmd="echo '#empty file supposed to be recreated' > tta/tests/Makefile.onetst; 
> touch -t 200001010000 tta/tests/Makefile.onetst"
> echo "  $cmd"
> $chicken eval $cmd || exit 1
> 
> Advices, ideas?
> 
> -- 
> Pat
> 

Reply via email to