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

  • Your .profile might have a check in it for interactive usage. Without seeing what it does, there's no telling.
    – muru
    Oct 5, 2021 at 8:28
  • Good point, updated. Oct 5, 2021 at 8:34
  • Now the same comment, but with .bashrc instead of .profile.
    – muru
    Oct 5, 2021 at 8:44
  • 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.
    – terdon
    Oct 5, 2021 at 8:45
  • Yep, that was correct. Solved it. Thank you. Oct 5, 2021 at 8:45

1 Answer 1


In .bashrc:

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

Following command works fine:

/bin/bash -ic "source ~/.bashrc"
  • 3
    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.
    – terdon
    Oct 5, 2021 at 8:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .