Shell variables stay local until they are exported. Exported names become environment variables for child processes.

Program

Play the script to choose a profile, export it, and read it from a child shell.

export_child_env.sh
#!/usr/bin/env bash

profile=
export APP_PROFILE="$profile"
child_value=$(bash -c 'printf "%s" "$APP_PROFILE"')
echo "child=$child_value"
#!/usr/bin/env bash

profile=
export APP_PROFILE="$profile"
child_value=$(bash -c 'printf "%s" "$APP_PROFILE"')
echo "child=$child_value"
#!/usr/bin/env bash

profile=
export APP_PROFILE="$profile"
child_value=$(bash -c 'printf "%s" "$APP_PROFILE"')
echo "child=$child_value"
export `export NAME=value` places a shell variable into the environment.
child process A child shell inherits exported variables from the parent shell.
local variable Without export, ordinary shell variables are not part of the child environment.