How to load an additional file when bash starts

Bash will issue automatic profiles such as .bashrc. The option --rcfilecan be used to override the automatic script. But when starting the bash> shell, I need to specify an additional personalized file (automatic script plus another file) without touching ANY files in the directory $HOMEor/etc , since the $HOMEdirectory belongs to the application user. The personal file should not be in the directory $HOME. Is it possible?

I tried:

    /bin/bash <<EOF
    . /a-directory-outside-of-home/vanilla
    EOF

but he returned to the current shell.

+6
source share
4 answers

, .bashrc, script, , bash, ?

:

/bin/bash --rcfile myscript

myscript:

source $HOME/.bashrc
+4
bash --rcfile <(cat rcfile1; cat rcfile2)

.

0

.bashrc. .bash_profile , $HOME.

, .bashrc.

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
  . ~/bashrc
fi

.personalized_settings .

# Adding personalized settings
if [ -f ~/.personalized_settings ]; then
  . ~/personalized_settings
fi

, .personalized_settings $HOME.

Fedora12.

Edit : You may have to search .profileinstead .bash_profilein Ubuntu (and hopefully other Debian based systems). (courtesy @Benjamin W.)

This (link) [ https://www.gnu.org/software/bash/manual/bash.html#Bash-Startup-Files] will give you more information about this.

What if you mess with any profile files?

You have a backup of all these files in /etc/skelwhich you could use to restore.

-1
source

Source: https://habr.com/ru/post/1617767/


All Articles