LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-02-2020, 08:16 AM   #1
salmanahmed
Member
 
Registered: Jun 2020
Posts: 158

Rep: Reputation: Disabled
Moving bash files to relevant directory


Hi
My home directory contains following bash related files:
Code:
.bash_aliases          .bash_functions  .bash_logout   .bashrc
.bash_eternal_history  .bash_history    .bash_profile  .bash_variables
I want to move all these files in a directory (~/.bash). I know how to move all these files and make relevant changes in .bashrc file. When I login, my bash loads ~/.bash_profile file and by making following changes in the contents of ~/.bash_profile I can move ~/.bashrc and other files to ~/.bash:
Code:
# ~/.bash_profile
#

[[ -f ~/.bash/.bashrc ]] && . ~/.bash/.bashrc
But I don't know how can I move ~/.bash_profile itself, as it is the first file which bash looks for after login. So where should I make changes so that bash looks in ~/.bash directory for .bash_profile?
Thanks
 
Old 07-02-2020, 08:35 AM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,242

Rep: Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322
You can't. BASH is hardcoded to look for .bash_profile in the root of your home directory.

From the bash-5.0 source code (all indentation preserved):

Code:
      /* Execute /etc/profile and one of the personal login shell
	 initialization files. */
      if (no_profile == 0)
	{
	  maybe_execute_file (SYS_PROFILE, 1);

	  if (act_like_sh)	/* sh */
	    maybe_execute_file ("~/.profile", 1);
	  else if ((maybe_execute_file ("~/.bash_profile", 1) == 0) &&
		   (maybe_execute_file ("~/.bash_login", 1) == 0))	/* bash */
	    maybe_execute_file ("~/.profile", 1);
	}

Last edited by dugan; 07-02-2020 at 08:39 AM.
 
4 members found this post helpful.
Old 07-02-2020, 09:09 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
yes, those files should be there, the location (and name) is hardcoded. Even .bashrc has a default name and location (which can be modified), but easier to keep it as is.
 
1 members found this post helpful.
Old 07-02-2020, 09:14 AM   #4
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
But nothing prevents you from
Code:
mkdir ~/.bash
for f in aliases functions variables
do mv ~/.bash_$f ~/.bash/$f
done
sed -Ei 's,\.bash_(aliases|functions|variables),.bash/\1,g' ~/.bashrc

Last edited by shruggy; 07-02-2020 at 10:02 AM.
 
1 members found this post helpful.
Old 07-02-2020, 09:54 AM   #5
salmanahmed
Member
 
Registered: Jun 2020
Posts: 158

Original Poster
Rep: Reputation: Disabled
Thanks a lot.
I was thinking that it can be done by /etc/profile.
 
Old 07-02-2020, 10:13 AM   #6
salmanahmed
Member
 
Registered: Jun 2020
Posts: 158

Original Poster
Rep: Reputation: Disabled
I have moved all ~/.bash* files except ~/.bash_profile and ~/.bashrc.
Initially, I had also moved ~/.bashrc to ~/.bash.d/.bashrc and adjust ~/.bash_profile as follows:
Code:
# ~/.bash_profile
#

[[ -f ~/.bash.d/.bashrc ]] && . ~/.bash.d/.bashrc
But bash did not recognize ~/.bash.d/.bashrc. So it looks like that ~/.bashrc is also hardcoded!
 
Old 07-02-2020, 11:52 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
you need to read the man page of bash and you will see how and when will these files be processed (look for invocation).
 
1 members found this post helpful.
Old 07-03-2020, 04:32 AM   #8
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by salmanahmed View Post
Thanks a lot.
I was thinking that it can be done by /etc/profile.
Why did you not include this thought in your original question?
It's possible, but fragile:
- does it really apply to all users?
- what if any of the files bash wants to source automagically is present?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Text file processing, using bash script for grabbing all relevant VPN config from ASA contra04 Linux - General 1 11-06-2014 02:35 AM
Bash: < & > order is relevant; but why unrelated i/o misordering hangs my pipes? romagnolo Linux - General 3 02-14-2012 09:29 AM
Relevant Info for Faster Answers PatrickNew Linux - Newbie 0 10-30-2006 09:41 AM
LXer: Report: How Relevant is the Homeland Security Grant? LXer Syndicated Linux News 0 01-23-2006 01:46 PM
Fedora Core 3: How to get the kernel source code into the relevant directories? Madhavikutty Fedora 5 03-10-2005 03:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration