0

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?

LuisF
  • 564
  • 1
  • 7
  • 18
  • `source` or start a new shell. Ah you don't want those... Strange. Well, I saw a duplicate question a couple of months ago with a crazy technique (which I wouldn't recommend...). Good luck finding it. – Karoly Horvath Nov 05 '15 at 10:36
  • The thing is that I want to run the script which includes new commands and then have them immediately available. Inside my new .bashrc I'm sourcing the custom dotfiles but that doesn't appear to be working (I guess it's because what I said, the script runs in its own shell) – LuisF Nov 05 '15 at 10:40
  • Any sane explanation why you *don't* want to source .bashrc? – Karoly Horvath Nov 05 '15 at 10:41
  • I'm sourcing .bashrc inside the script... – LuisF Nov 05 '15 at 10:42
  • 1
    *After* the script finishes. – Karoly Horvath Nov 05 '15 at 10:42
  • Just being stubborn, I would guess sourcing inside the script would work or that at least a simple solution existed. If not...oh well...I don't mind doing it :) – LuisF Nov 05 '15 at 10:44
  • You need a function (or at least a function wrapper), not a script. But I honestly don't see what's so hard about opening a new shell. – 4ae1e1 Nov 05 '15 at 11:28
  • Not hard at all, just curious :) – LuisF Nov 05 '15 at 11:33

1 Answers1

0

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

Community
  • 1
  • 1
LuisF
  • 564
  • 1
  • 7
  • 18