Add WORK_COLOR=green to ~/.bashrc.
Apply it to the current Bash without creating a child shell.
Which command is appropriate?
source FILE executes the file in the current shell, so variables, functions, and aliases defined there remain available in that shell.
Detailed explanation
bash ~/.bashrcIncorrect. bash ~/.bashrc runs in a child Bash, so changes do not return to the parent.
Incorrect. bash ~/.bashrc runs in a child Bash, so changes do not return to the parent.
source ~/.bashrcCorrect. source ~/.bashrc reads the file in the current shell.
Correct. source ~/.bashrc reads the file in the current shell.
exec ~/.bashrcIncorrect. exec would replace the current shell with an attempted file execution.
Incorrect. exec would replace the current shell with an attempted file execution.
export ~/.bashrcIncorrect. export handles variable attributes, not file inclusion.
Incorrect. export handles variable attributes, not file inclusion.
Try it yourself
An example you can run in a temporary verification environment.
bash --noprofile --norc -c 'f=$(mktemp); printf "WORK_COLOR=green\n" >"$f"; source "$f"; printf "%s\n" "$WORK_COLOR"; rm -f "$f"'Expected result
greenKey points
- source uses the current shell
- It does not create a child shell
- Definitions remain in the current environment
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.