-2

I'm writing a bash script that executes some commands and at the end it must execute the command:

source .bashrc

When executing my bash script ./test.sh, all commands are executed except for the source .bashrc, it seems not to be executed.

So is there a way i can force source .bashrc to be executed in the bash script?

3
  • How do you conclude that it's not running? Please edit to show the output from bash -x. I bet this is actually going to reveal that it runs it just fine, but you expected the environment to be changed when the script finsihes, which of course won't be true. Commented Mar 16, 2021 at 20:07
  • @tripleee. I believe you were a bit in hurry considering that it is running. the program i'm trying to install via bash scripts checks if some variables are available in .bashrc. So supposing that source ~/.bashrc is running or being executed inside the script, the changes that my program makes does not take effect, unless i run source .bashrc again and outside the script Commented Mar 16, 2021 at 20:17
  • @k.jbaili : If you execute a source command, it either runs or produces an error message. To find out why it is not executed, run the calling script with -x and analyze the trace. Having said this, I find it very odd that someone is sourcing ~/.bashrc from some script, and even more, at the end of that script. A well written .bashrc contains only variable- or environment settings for an interactive shell, and would have no effect at all at the end of a script. Commented Mar 17, 2021 at 11:01

1 Answer 1

0

Try:

source ~/.bashrc

Instead. It could be that you're executing the script from somewhere other than the home directory and so source doesn't pick up your bashrc file.

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

3 Comments

Tried this before. Didn't work unfortunately
Try it with my edit of having an explicit path (in case you can't see it, instead of doing ~/.bashrc do /home/<username>/.bashrc).
@wxz. Also doesn't work. Seems not doable!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.