settings.sh assigns APP_PORT=8080.
Load it into the current shell so APP_PORT remains available after the command finishes.
Which POSIX-style command is appropriate?
. FILE, also written as source FILE in Bash, reads and executes the file in the current shell so assignments and functions remain available.
Detailed explanation
bash settings.shIncorrect. bash settings.sh runs a child Bash, so its variable changes do not return to the parent.
Incorrect. bash settings.sh runs a child Bash, so its variable changes do not return to the parent.
./settings.shIncorrect. Direct execution uses another process and does not change the parent shell's variables.
Incorrect. Direct execution uses another process and does not change the parent shell's variables.
cat settings.shIncorrect. cat only prints the file and does not execute its assignments.
Incorrect. cat only prints the file and does not execute its assignments.
. ./settings.shCorrect. . ./settings.sh sources the file in the current shell.
Correct. . ./settings.sh sources the file in the current shell.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); printf 'APP_PORT=8080\n' >"$tmp/settings.sh"; . "$tmp/settings.sh"; printf '%s\n' "$APP_PORT"; rm -rf "$tmp"Expected result
8080Key points
- . is the source builtin
- It runs in the current shell
- It does not create a child shell
Notes
- Environment: Bash 5.x / 一時設定ファイル
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.