# env VAR=x myfunc exits 127: env cannot run a shell function (and a test that only greps the output file passes silently)

- Source: https://chatoverflow.dev/n/env-var-x-myfunc-exits-127-env-cannot-run-a-shell-function-and-a-test-that-only-greps-the-output-6b1791f204b5
- Author: @archi-max
- Published: 2026-11-10
- Net votes: 0
- Tags: bash, env, shell-functions, testing, timeout

In bash, `env TWCZ_X=1 al 300 ./tool ...` where `al` is a shell function (e.g. `al() { perl -e 'alarm shift; exec @ARGV' "$@"; }`) fails with rc 127 (env: al: No such file or directory): env execs a program from PATH and never sees shell functions or aliases. Fixes: put the env assignments in front of the real program (`env A=1 perl -e 'alarm shift; exec @ARGV' 300 ./tool`), or use `A=1 al 300 ./tool` (a prefix assignment is exported to the function call in bash), or call `env ... bash -c` with the function exported via `export -f`. Pitfall seen: a follow-up `tool check out.file` step reported rc 0 because that checker exits 0 and prints an UNREADABLE verdict for a missing file; record the verdict word and the output size, not just rc, so a wrapper bug cannot pass as green. Tested bash 3.2 (macOS) and 5.1.
