]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: env/env.sh: improve portability
authoroech3 <79379754+oech3@users.noreply.github.com>
Thu, 12 Mar 2026 09:33:08 +0000 (18:33 +0900)
committerPádraig Brady <P@draigBrady.com>
Fri, 27 Mar 2026 21:15:18 +0000 (21:15 +0000)
* tests/env/env.sh: Make more portable by avoiding references to our
build dir,  and avoiding names that may cause false matches in
multi-call binaries.
https://github.com/coreutils/coreutils/pull/216

tests/env/env.sh

index d68c11a2254d465423978e6e7bd5cd7bbb4cefba..425a8272438aeef059dd3b751bf88c7c12f96165 100755 (executable)
 print_ver_ env pwd nice
 
 # A simple shebang program to call "echo" from symlinks like "./-u" or "./--".
-echo "#!$abs_top_builddir/src/echo simple_echo" > simple_echo \
+echo '#!'"$(command -v env | sed 's|/env|/echo|')"' foo' > show_args \
   || framework_failure_
-chmod a+x simple_echo || framework_failure_
+chmod a+x show_args || framework_failure_
 
 # Verify we can run the shebang which is not the case if
 # there are spaces in $abs_top_builddir.
-./simple_echo || skip_ "Error running simple_echo script"
+./show_args || skip_ "Error running show_args script"
 
 # Verify clearing the environment
 a=1
@@ -117,9 +117,9 @@ export PATH
 # On some systems, execve("-i") invokes a shebang script ./-i on PATH as
 # '/bin/sh -i', rather than '/bin/sh -- -i', which doesn't do what we want.
 # Avoid the issue by using a shebang to 'echo' passing a second parameter
-# before the '-i'. See the definition of simple_echo before.
+# before the '-i'. See the definition of show_args before.
 # Test -u, rather than -i, to minimize PATH problems.
-ln -s "simple_echo" ./-u || framework_failure_
+ln -s "show_args" ./-u || framework_failure_
 case $(env -u echo echo good) in
   good) ;;
   *) fail=1 ;;
@@ -135,7 +135,7 @@ esac
 
 # After options have ended, the first argument not containing = is a program.
 returns_ 127 env a=b -- true || fail=1
-ln -s "simple_echo" ./-- || framework_failure_
+ln -s "show_args" ./-- || framework_failure_
 case $(env a=b -- true || echo fail) in
   *true) ;;
   *) fail=1 ;;