bash resource doesn't seem to be loading my .bashrc file

1.9k views Asked by At

I am having some trouble trying to load my .bashrc file through the bash Chef resource. My .bashrc is located in /sh/.bashrc This is my resource code:

bash "Source .bashrc" do
    cwd "/home/ameya"
    user "ameya"
    code "source /sh/.bashrc"
    action :run
end

My .bashrc has only the following bit:

export ME=ameya

So when I type echo $ME at the terminal I expect to see it print out ameya but nothing gets printed out. What is wrong with the way I have set things up? Thanks in advance

1

There are 1 answers

2
Charles Duffy On BEST ANSWER

The .bashrc for the user ameya is /home/ameya/.bashrc. If you want it to run a shared file, you might do the following:

file "/home/ameya/.bashrc" do
  content "source /home/sh/.bashrc"
done

When Chef runs /home/sh/.bashrc, the effect only lasts as long as that single shell instance, started by Chef, is running. If you want the effects of a .bashrc file to take effect on every interactive shell invocation, you need to arrange for it to be source'd during that startup process.