I am trying to source my .bashrc file on remote host inside sudo-less user. I am getting following responses.

sh-4.2$ source .bash_profile
sh-4.2$ source: .bash_profile: file not found

sh-4.2$ source ~/.bash_profile
[user@hera ~]$

Why is this behavior?

added image

contents of .bash_profile

contents of .bashrc

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc

# Uncomment the following line if you don't like systemctl's auto-paging feature:

# User specific aliases and functions

# added by Anaconda3 4.1.1 installer
export PATH="/home/tensorflow/anaconda3/bin:$PATH"
  • Something funny going on, you're supposed to see bash: .bashrc: No such file or directory if .bashrc cannot be found. – Ryan Babchishin Sep 16 '16 at 20:28
  • Why does your command prompt look like that and what shell are you using? What OS? Why didn't your .bashrc load when you logged in? – Ryan Babchishin Sep 16 '16 at 20:35
  • I know .bash_profile, not .bashrc – Ryan Babchishin Sep 16 '16 at 21:29
  • @RyanBabchishin, added the image for clearing your doubts – v78 Sep 16 '16 at 22:12
  • I'm just wondering about the funny error message. You should be getting the one I showed you. Can you verify what your default shell is? grep dd2 /etc/passwd will tell you. Can you post the contents of .bash_profile? And the output of help source? – Ryan Babchishin Sep 16 '16 at 22:40

You are using bash in POSIX mode.

From man bash under source filename [arguments]

If filename does not contain a slash, file names in PATH are used to find the directory containing filename... When bash is not in posix mode, the current directory is searched if no file is found in PATH.

Bash is running in posix mode because you have started it as sh rather than bash (thus the command prompt being sh-4.2). You will need to change your shell to /bin/bash in order to use "bash-isms" like this.

  • Bingo! Nice one... never seen that before. – Ryan Babchishin Sep 16 '16 at 22:42

you can see what is the path with pwd command - i bet that your .bashrc is not in the current working directory

  • no, pwd is right. Even tab-auto-complete is completing it. – v78 Sep 16 '16 at 20:04
  • both my .bashrc and .bash_profile are in home/user directory. – v78 Sep 16 '16 at 20:11
  • ~/.bash_profile expands to /home/user/.bash_profile , so that is why it is working. when you login via ssh it seems that it cannot find it, so i've assumed user sits in the wrong directory. (assuming things - shame on me). hope you will get better answer :) – Martynas Saint Sep 16 '16 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.