Environment and PATH
Command Environment
Prefix One Run
A variable assignment before a command sets an environment value for that command invocation without changing the whole script.
Program
Play the script to choose a log level and build the one-command environment prefix.
command_env.sh
Replay: real traced execution (multi-file project)
#!/usr/bin/env bash
level="info"
command="LOG_LEVEL=$level ./run-report"
echo "$command"
#!/usr/bin/env bash
level="debug"
command="LOG_LEVEL=$level ./run-report"
echo "$command"
#!/usr/bin/env bash
level="warn"
command="LOG_LEVEL=$level ./run-report"
echo "$command"
level ← info
3level="info"4command="LOG_LEVEL=$level ./run-report"values this stepinfolevelcommand ← LOG_LEVEL=info ./run-report
3level="info"4command="LOG_LEVEL=$level ./run-report"5echo "$command"values this stepLOG_LEVEL=info ./run-reportcommandinfolevelecho "$command"
4command="LOG_LEVEL=$level ./run-report"5echo "$command"outputLOG_LEVEL=info ./run-reportvalues this stepLOG_LEVEL=info ./run-reportcommand
level ← debug
3level="debug"4command="LOG_LEVEL=$level ./run-report"values this stepdebuglevelcommand ← LOG_LEVEL=debug ./run-report
3level="debug"4command="LOG_LEVEL=$level ./run-report"5echo "$command"values this stepLOG_LEVEL=debug ./run-reportcommanddebuglevelecho "$command"
4command="LOG_LEVEL=$level ./run-report"5echo "$command"outputLOG_LEVEL=debug ./run-reportvalues this stepLOG_LEVEL=debug ./run-reportcommand
level ← warn
3level="warn"4command="LOG_LEVEL=$level ./run-report"values this stepwarnlevelcommand ← LOG_LEVEL=warn ./run-report
3level="warn"4command="LOG_LEVEL=$level ./run-report"5echo "$command"values this stepLOG_LEVEL=warn ./run-reportcommandwarnlevelecho "$command"
4command="LOG_LEVEL=$level ./run-report"5echo "$command"outputLOG_LEVEL=warn ./run-reportvalues this stepLOG_LEVEL=warn ./run-reportcommand
environment prefix
`NAME=value command` sets `NAME` only for that command run.
temporary value
The prefix is useful when one command needs a setting but the script should not export it globally.
command plan
This example prints command text instead of executing a project-specific program.