From 716cb6f1ef32742ecfc1d05831a1b8aadceb0316 Mon Sep 17 00:00:00 2001 From: Taylor Buchanan Date: Tue, 16 Jun 2026 13:46:39 -0500 Subject: [PATCH] Resolve sh from PATH for generated stub scripts _shunit_mktempFunc writes its stub scripts (including the noexec exec-permission probe) with a hardcoded #!/bin/sh. On systems without /bin/sh the stubs cannot exec, so the noexec probe fails and shUnit2 aborts with a misleading "declare TMPDIR ... exec permission" error even when TMPDIR is executable. This affects non-FHS layouts such as NixOS (#185) and Termux (where sh lives under $PREFIX/bin). Resolve sh from PATH via `command -v sh`. Unlike #!/usr/bin/env sh it does not assume /usr/bin/env exists either, and on FHS systems it still resolves to /bin/sh, so behavior is unchanged there. Refs #185. Co-Authored-By: Claude Opus 4.8 (1M context) Signed-off-by: Taylor Buchanan --- shunit2 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/shunit2 b/shunit2 index 7cb5a57..2207609 100755 --- a/shunit2 +++ b/shunit2 @@ -1119,17 +1119,20 @@ _shunit_mktempDir() { # Args: # None _shunit_mktempFunc() { + # Not every system provides /bin/sh, so resolve sh from PATH rather than + # hardcoding the stub interpreter. + _shunit_sh_=`command -v sh` for _shunit_func_ in oneTimeSetUp oneTimeTearDown setUp tearDown suite noexec do _shunit_file_="${__shunit_tmpDir}/${_shunit_func_}" command cat <"${_shunit_file_}" -#! /bin/sh +#!${_shunit_sh_} exit ${SHUNIT_TRUE} EOF command chmod +x "${_shunit_file_}" done - unset _shunit_file_ + unset _shunit_file_ _shunit_sh_ } # Final cleanup function to leave things as we found them.