Posts

Showing posts with the label Bashrc

Cannot Successfully Source .bashrc From A Shell Script

Answer : A shell script is run in its own shell instance. All the variable settings, function definitions and such only affect this instance (and maybe its children) but not the calling shell so they are gone after the script finished. By contrast the source command doesn't start a new shell instance but uses the current shell so the changes remain. If you want a shortcut to read your .bashrc use a shell function or an alias instead of a shell script, like alias brc='source ~/.bashrc' I want to complement ravi's answer: This behavior is specific to Ubuntu (and probably most derived distros), since your default ~/.bashrc file starts with a short-circuit, Ubuntu 18.04, for example: # If not running interactively, don't do anything case $- in *i*) ;; *) return;; esac That will stop the evaluation of the file if it is running in a non-interactive shell, which is the case of your script since all scripts are run in a non-interactive shell, and...