Read ./env.conf in the current shell and keep its variable definitions.
Use the POSIX form instead of source.
Which command is appropriate?
. FILE is the POSIX dot command for reading and executing a file in the current shell. It serves the same purpose as Bash source.
Detailed explanation
sh ./env.confIncorrect. sh ./env.conf runs in a separate process.
Incorrect. sh ./env.conf runs in a separate process.
./env.confIncorrect. Executing the file directly is not the current-shell include operation.
Incorrect. Executing the file directly is not the current-shell include operation.
. ./env.confCorrect. . ./env.conf reads the file in the current shell.
Correct. . ./env.conf reads the file in the current shell.
cat ./env.confIncorrect. cat only displays the file and does not execute assignments.
Incorrect. cat only displays the file and does not execute assignments.
Try it yourself
An example you can run in a temporary verification environment.
sh -c 'f=$(mktemp); printf "DEMO_DOT=loaded\n" >"$f"; . "$f"; printf "%s\n" "$DEMO_DOT"; rm -f "$f"'Expected result
loadedKey points
- Dot is a shell builtin
- It runs in the current shell
- It is more portable than source
Notes
- Environment: POSIX sh / 一時ファイル
- 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.