Interview Prep/Shell Scripting/Arguments, I/O, here-docs, process substitution and subshells

How do you run a group of commands with a different environment without affecting the script?

IntermediateConceptArguments, I/O, here-docs, process substitution and subshells
Answer
AWS_PROFILE=prod AWS_REGION=ap-south-1 aws s3 ls          # one command
env -i PATH=/usr/bin:/bin HOME="$HOME" ./build.sh          # clean environment
( export KUBECONFIG=~/.kube/prod; kubectl get nodes; kubectl get pods -A )   # subshell

The VAR=value cmd prefix does not work for builtins in all cases and does not apply to commands after a pipe. env -i is a great way to reproduce "works in my shell, fails in cron" issues.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Arguments, I/O, here-docs, process substitution and subshells