Ubuntu – the difference between –init-file and –rcfile

bashbashrc

I've been working with bash, and I came across the --rcfile and --init-file options. Bash's man page lists these under the same section, but they seem to behave differently. Take the following scenario:

I have created a ~/.bash_profile which has the following command:

exec env -i <variables> /bin/bash <option> ~/.bashrc

for the purposes of a project which require the terminal to open with a specific configuration; it is instructed not to read /etc/bash.bashrc and instead only read from ~/.bashrc. If <option> is –init-file, ~/.bashrc is read without error. However, --rcfile in its place does not appear to source the file.

What is the difference between these two seemingly identical commands?

Best Answer

They are synonymous.

From the shell.c file of bash-4.3 source:

long_args[] = {
....
  { "init-file", Charp, (int *)0x0, &bashrc_file },
....
  { "rcfile", Charp, (int *)0x0, &bashrc_file },
....
};

As you can see they are defined the same way and also works the same way.

The parameter bashrc_file stores the filename.

For further assurance, the CHANGES file in the source contains:

Added a new '--init-file' invocation argument as a synonym for '--rcfile', per the new GNU coding standards.