Score:0

bash -c "source ~/.profile" doesn't source ~/.profile

es flag

Here's some output from inside a Docker container (running Ubuntu 18.04) which seems to be acting up.

# source ~/.profile
net.ipv4.ipfrag_high_thresh = 134217728
net.core.rmem_default = 10485760
sourcing /opt/ros/foxy/install/setup.bash
ROS_ROOT   /opt/ros/foxy
ROS_DISTRO foxy
# bash -c "source ~/.profile"
# /bin/bash -c "source /root/.profile"
# 

The output from the first command is something I expect from the following commands. Feels like I'm missing something obvious here. For context, I need /bin/bash -c "source /root/.profile" to work because I don't want to have to enter the Docker container in order to run my commands, and I want to run the stuff in .bashrc prior to running them. Where am I going wrong?

muru avatar
us flag
Your `.profile` might have a check in it for interactive usage. Without seeing what it does, there's no telling.
es flag
Good point, updated.
muru avatar
us flag
Now the same comment, but with `.bashrc` instead of `.profile`.
terdon avatar
cn flag
Yes, please [edit] your question and add i) the ENTIRE contents of your .bashrc and ii) the ENTIRE contents of your `~/.profile`. You could have anything at all in those files, we can't guess what you are trying to do. Ideally, show us only a minimal example, with as few lines as possible that actually reproduces the problem.
es flag
Yep, that was correct. Solved it. Thank you.
Score:-2
es flag

In .bashrc:

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

Following command works fine:

/bin/bash -ic "source ~/.bashrc"
terdon avatar
cn flag
Note that this isn't very useful. You only source the file into the `bash -c` shell, so any variables you define in the file will not be available to the parent shell. As soon as the `/bin/bash` process ends, the variables are gone and you're back where you started. Just run `. ~/.bashrc` directly.
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.