大网数据广告活动
服务器运维问答

'source .bash_profile' fails but 'source path/to/.bash_profile' works

· 52CE 我爱测

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 ~]…

问题原文

原帖链接 · v78 · CC BY-SA 3.0

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"

已采纳解答

原帖链接 · DerfK · CC BY-SA 3.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-09-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。