.profile, .bash_profile, .bash_aliases, etc

New to Debian (Or Linux in general)? Ask your questions here!

.profile, .bash_profile, .bash_aliases, etc

Postby PsySc0rpi0n » 2020-02-01 14:26

Hello.

I have this quick question about these files.
The name of these files have any consequence? I mean, if I use one instead of the other with the same code inside, do they run all the code, or the code being ran will depend on the name of the file?
Is it different to have the same content in one or the other file, or the same code will run in either of them?

I have all the above files and I'm not sure I can gather all the code in a single file and stick to it instead of having several files!

Thanks
Psy
User avatar
PsySc0rpi0n
 
Posts: 216
Joined: 2012-10-24 13:54
Location: Portugal

Re: .profile, .bash_profile, .bash_aliases, etc

Postby Head_on_a_Stick » 2020-02-01 15:55

I keep things simple and just use ~/.profile because that is read by all shells.

If you create ~/.bash_profile then bash won't read ~/.profile so you'll have to either source it or copy the contents over.
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 12770
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: .profile, .bash_profile, .bash_aliases, etc

Postby PsySc0rpi0n » 2020-02-01 17:32

Ok, an what happens in the background when you issue
Code: Select all
source file
???
User avatar
PsySc0rpi0n
 
Posts: 216
Joined: 2012-10-24 13:54
Location: Portugal

Re: .profile, .bash_profile, .bash_aliases, etc

Postby Head_on_a_Stick » 2020-02-01 17:56

From the bash man page:
Code: Select all
       source filename [arguments]
              Read and execute commands from filename in the current shell en‐
              vironment  and  return  the exit status of the last command exe‐
              cuted from filename.  If filename  does  not  contain  a  slash,
              filenames  in  PATH  are  used  to find the directory containing
              filename.  The file searched for in PATH need not be executable.
              When  bash  is  not  in  posix  mode,  the  current directory is
              searched if no file is found in PATH.  If the sourcepath  option
              to  the  shopt  builtin  command  is turned off, the PATH is not
              searched.  If any arguments are supplied, they become the  posi‐
              tional  parameters when filename is executed.  Otherwise the po‐
              sitional parameters are unchanged.  If the -T option is enabled,
              source  inherits any trap on DEBUG; if it is not, any DEBUG trap
              string is saved and restored around  the  call  to  source,  and
              source  unsets  the  DEBUG trap while it executes.  If -T is not
              set, and the sourced file changes the DEBUG trap, the new  value
              is  retained  when  source  completes.  The return status is the
              status of the last command exited within the  script  (0  if  no
              commands  are  executed),  and false if filename is not found or
              cannot be read.

Note that the source command is a bashism. To source files with other shells use the . ("dot") command instead (which will also work with bash): https://pubs.opengroup.org/onlinepubs/9 ... 2.html#dot
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 12770
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: .profile, .bash_profile, .bash_aliases, etc

Postby PsySc0rpi0n » 2020-02-02 10:16

Ok, thank you.

So, if I copy contents from files .bash_profile, .bash_aliases all into .profile, I'll be good, right?
User avatar
PsySc0rpi0n
 
Posts: 216
Joined: 2012-10-24 13:54
Location: Portugal

Re: .profile, .bash_profile, .bash_aliases, etc

Postby Head_on_a_Stick » 2020-02-02 11:04

Yes.
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 12770
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: .profile, .bash_profile, .bash_aliases, etc

Postby peter_irich » 2020-02-02 12:29

See "man bash", INVOCATION, to hear the these scripts calling order.
peter_irich
 
Posts: 1299
Joined: 2009-09-10 20:15
Location: Saint-Petersburg, Russian Federation

Re: .profile, .bash_profile, .bash_aliases, etc

Postby PsySc0rpi0n » 2020-02-02 22:09

Thank you both...

I'm reading that INVOCATION!
User avatar
PsySc0rpi0n
 
Posts: 216
Joined: 2012-10-24 13:54
Location: Portugal


Return to Beginners Questions

Who is online

Users browsing this forum: arzgi and 12 guests

fashionable