Search code examples
bashshellshdotfiles

How to source a file via shell script


I wrote a shell script where I copy my .bashrc file as well as custom dotfiles to a backup folder and then replace them in my home folder with another .bashrc file which will then source my custom dotfiles.

However, after the script does its job, if I try to execute the aliases I included in the new files I get the error No command found. Only after I source the .bashrc file manually in the terminal I have access to them.

From what I understand, the script I'm running is executing in a sub-shell (?) which will terminate on execution.

How can I run the script and have new commands/aliases/functions available without having to source the .bashrc file myself or restarting the terminal?


Solution

  • Well, it appears that instead of running my script via sh script.sh, I can source it like source script.sh, which will behave exactly as I wanted.

    Solution