Safer Bash Shebang Recipes
If you’re writing a bash shebang recipe, consider adding set -euxo pipefail:
foo:
#!/usr/bin/env bash
set -euxo pipefail
hello='Yo'
echo "$hello from Bash!"
It isn’t strictly necessary, but set -euxo pipefail turns on a few useful
features that make bash shebang recipes behave more like normal, linewise
just recipe:
-
set -emakesbashexit if a command fails. -
set -umakesbashexit if a variable is undefined. -
set -xmakesbashprint each script line before it’s run. -
set -o pipefailmakesbashexit if a command in a pipeline fails. This isbash-specific, so isn’t turned on in normal linewisejustrecipes.
Together, these avoid a lot of shell scripting gotchas.
Shebang Recipe Execution on Windows
On Windows, shebang interpreter paths containing a / are translated from
Unix-style paths to Windows-style paths using cygpath, a utility that ships
with Cygwin.
For example, to execute this recipe on Windows:
echo:
#!/bin/sh
echo "Hello!"
The interpreter path /bin/sh will be translated to a Windows-style path using
cygpath before being executed.
If the interpreter path does not contain a / it will be executed without
being translated. This is useful if cygpath is not available, or you wish to
pass a Windows-style path to the interpreter.