Score:0

~/.bashrc displays entries depending on how it is called

cz flag

I am trying to export a new directory "foo" to $PATH using a shell script. For now I used a shell script install.sh that exports the path like this:

<install.sh> 
#! /bin/sh

echo export PATH=$PATH:<path/foo> >> ~/.bashrc

For some reason, if I now try to display the ~/.bashrc file, I do get different outputs depending on how I print it. For example, accessing it in a Terminal via vi ~/.bashrc will display the file without my exported line. However, if I load it via a shell script (the same command but in a .sh file), my exported line is shown. I have no other way to see this line, except through this method. I already checked different versions of the command with different shebangs (bin/sh vs bin/bash) and with/without sudo. Where is my added line stored? I already checked /etc/skel/.bashrc and ~/.bashrc.

(I know that it adds a new export line every time the script gets called. Using Ubuntu 22.04.2 LTS).

EDIT:

calling the install.sh script with sudo script sets the $PATH variable as root and calling it as user returns the user $PATH variable as user which caused this behaviour.

mook765 avatar
cn flag
Do you run the terminal command and the script as the same user?
raj avatar
cn flag
raj
Type the command `echo ~` directly in your terminal, and then run the same command in a shell script. See if there is a difference in the directory name that is printed.
Herbert Qerbert avatar
cz flag
Thank you for the quick help. This seems to resolve the issue. The script set the $PATH variable as root and calling it as user returns the user $PATH variable.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.