bash does not load variables

Asked 2 years ago, Updated 2 years ago, 202 views

Does not read variables in files with bash through/.profile or through/.bash_profile.
For example, in .bash_profile,

export x=100

as
echo$x

does not print a value of x.
The /etc/profile setting is

#System-wide.profile for sh(1)

if [-x/usr/libexec/path_helper]; then
        val`/usr/libexec/path_helper-s`
fi

if ["${BASH-no}"!="no"; then
        [-r/etc/bashrc] & ./etc/bashrc
fi

is shown in .

bash

2022-09-30 21:43

3 Answers

By default, through /.profile and through /.bash_profile are read when the login shell boots.
Booting as a login shell like bash-l or bash--login will work as desired.


2022-09-30 21:43

At that time, sh used .profile at startup.

Currently bash attempts to load .bash_profile first. However, if it does not exist, load .profile

If bash boots as sh (for example, /bin/sh is a link to /bin/bash), or if it boots with the --posix flag, try to emulate .profile

So try using ~/.bash_profile directly


2022-09-30 21:43

The environment variables described in ~/.bash_profile are enabled by:

  • Login again
  • Run
  • su- *Not enabled on su
  • Running source~/.bash_profile or .~/.bash_profile

If you write through /.bashrc, it will run every time bash is started.

As Renya Gaikon replied, ~/.profile and ~/.bash_profile seem to be loaded only when logging in.
After logging in, bash runs through /.bashrc in the current shell.
stThis is the result of starting bash in trace.

~/.bashrc in my environment runs /etc/bashrc in the current shell.. .bashrc remains the default

The following environments were tried:
CentOS Linux release 8.0.1905(Core)
GNU bash, version 4.4.19(1)-release(x86_64-redhat-linux-gnu)


2022-09-30 21:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.