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?

8
  • 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. Commented Nov 5, 2015 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) Commented Nov 5, 2015 at 10:40
  • Any sane explanation why you don't want to source .bashrc? Commented Nov 5, 2015 at 10:41
  • I'm sourcing .bashrc inside the script... Commented Nov 5, 2015 at 10:42
  • 1
    After the script finishes. Commented Nov 5, 2015 at 10:42

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.