Skip to content

Instantly share code, notes, and snippets.

@the-moog
Created September 13, 2023 13:02
Show Gist options
  • Save the-moog/b4346de2bb60347356cfa1cecf769aef to your computer and use it in GitHub Desktop.
Save the-moog/b4346de2bb60347356cfa1cecf769aef to your computer and use it in GitHub Desktop.
shebang: '/usr/bin/env /path/interpreter' or '/usr/bin/env interpreter'??

Running

Notice that #2 in the 2nd example is the only one that works

1: Without user PATH

./envtest1;./envtest2;./envtest3

diff <(cat env_envtest1) <(cat env_envtest2)
diff <(cat env_envtest2) <(cat env_envtest3)

2: With user PATH

cp /bin/whoami ./bash
PATH=$(pwd):${PATH}; { ./envtest1;./envtest2;./envtest3; }
diff <(cat env_envtest1) <(cat env_envtest2)
diff <(cat env_envtest2) <(cat env_envtest3)
#!/usr/bin/env bash
source envtestx
#!/usr/bin/env /bin/bash
source envtestx
echo -e "\n\nI am $0 ($*)"
logname="env_$(basename $0)"
rm -f "${logname}"
declare -a environ1
declare -a environ2
environ1=($(set))
environ2=($(env))
printf "'set': Length: %d\n" "${#environ1[@]}"
printf "'env': Length: %d\n" "${#environ2[@]}"
for each_item in "${environ1[@]}"; do
echo -e "${each_item}" > "${logname}"
done
for each_item in "${environ2[@]}"; do
echo -e "${each_item}" >> "${logname}"
done
ls -al env_*
#!/bin/bash
source envtestx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment