Edit ~/.profile.
Load it into the current Bash without starting a child shell.
Which command is appropriate?
source FILE, or . FILE, executes the file in the current shell so its variables and functions remain there.
Detailed explanation
source ~/.profileCorrect. source reads and executes ~/.profile in the current shell.
Correct. source reads and executes ~/.profile in the current shell.
bash ~/.profileIncorrect. bash starts a child shell, so changes do not return to the parent shell.
Incorrect. bash starts a child shell, so changes do not return to the parent shell.
exec ~/.profileIncorrect. exec replaces the current shell with a command rather than sourcing the file.
Incorrect. exec replaces the current shell with a command rather than sourcing the file.
export ~/.profileIncorrect. export handles variable attributes; it does not read a startup file.
Incorrect. export handles variable attributes; it does not read a startup file.
Try it yourself
An example you can run in a temporary verification environment.
bash --noprofile --norc -c 'profile=$(mktemp); printf "DEMO_VALUE=loaded\n" > "$profile"; source "$profile"; printf "%s\n" "$DEMO_VALUE"; rm -f -- "$profile"'Expected result
loadedKey points
- source uses current shell
- . is an alias
- Difference from a child shell
Notes
- Environment: GNU Bash 5.2 / 一時ファイル
- 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.