-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?

Khaled
  • 555
  • 1
  • 6
  • 26
  • 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. – tripleee Mar 16 '21 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 – Khaled Mar 16 '21 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. – user1934428 Mar 17 '21 at 11:01

1 Answers1

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.

hakmad
  • 39
  • 4