1

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
fi

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

# User specific aliases and functions

# added by Anaconda3 4.1.1 installer
export PATH="/home/tensorflow/anaconda3/bin:$PATH"
v78
  • 113
  • 6
  • 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
  • @RyanBabchishin, added what you wanted. – v78 Sep 16 '16 at 22:54
  • Is your home directory mounted dynamically? I have seen similar symptoms when the home directory has been lazily unmounted. – kasperd Sep 17 '16 at 00:15
  • @kasperd, by lazily do you mean sshfs? . I am sshing my remote server. – v78 Sep 17 '16 at 10:56
  • @dd2 No. `umount -l` is filesystem independent. But it looks like you found an explanation which had nothing to do with how the home directory is mounted. – kasperd Sep 17 '16 at 13:30

2 Answers2

5

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.

DerfK
  • 19,493
  • 2
  • 38
  • 54
0

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

Martynas Saint
  • 1,221
  • 7
  • 15
  • 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