~/.bashrc
is usually read for secondary interactive shells after you log in. If you want to initialise your parameters on login the use ~/.profile
instead. To apply you parameters system-wide use /etc/profile
. It's the first file read by bash.
To make things clearer I think I'd explain a bit more.
- When you login, your login shell reads first the global
/etc/profile
, then ~/.profile
and parameters/variables mentioned there are initialised. However you don't see this shell as terminal because the X-window system GUI is running.
- After login when you open a secondary terminal/terminal-emulator e.g.
gnome-terminal
~/.bashrc
is read and and the parameters/variables declared in it are available to the secondary terminal only. Note that this secondary terminal is a child process of your login shell.
- When you launch an application from menu, it's executed as a child process of your login shell and it inherits the parameters from it's ancestor process. But
.bashrc
was not available for the main login shell; so it's not available for applications too. So anything in .bashrc
won't be available for those applications if run from menu. But when you open a gnome-terminal
and executes command from there, applications are launched as children of gnome-terminal
and inherits .bashrc
's parameters from it.
If you're opening just one file, you don't really need to use a script, because a script is meant to be an easy way to run multiple commands in a row, while here you just need to run two commands (including exit
).
If you want to run exit
after a command or after a chain of commands, you can chain it to what you have already by using the &&
operator (which on success of the previous command / chain of commands will execute the next command) or by using the ;
operator (which both on success and on failure of the previous command / chain of commands will execute the next command).
In this case it would be something like that:
gnome-open <path_to_pdf_file> && exit
*<path_to_pfd_file> = path of the pdf file
exit
put at the end of a script doesn't work because it just exits the bash
instance in which the script is run, which is another bash
instance than the Terminal's inner bash
instance.
If you want to use a script anyway, the most straightforward way it's to just call the script like so:
<path_to_script> && exit
Or if the script is in the Terminal's current working directory like so:
./<script> && exit
If you really don't want to / can't do that, the second most straightforward way is to add this line at the end of your script:
kill -9 $PPID
This will send a SIGKILL
signal to the to the script's parent process (the bash
instance linked to the Terminal). If only one bash
instance is linked to the Terminal, that being killed will cause Terminal to close itself. If multiple bash
instances are linked to the Terminal, that being killed won't cause Terminal to close itself.
Best Answer
In a nutshell:
To open a new terminal window with the same full history as the current session, run:
Full explanation:
The Bash history works like this:
$HISTFILE
, which is usually~/.bash_history
.$HISTFILE
on the disk.Note that for both the temporary and the persistent history may have size limits and get truncated when they become too long.
As each Bash instance only writes to a temporary history in your memory, the actions from a running session do not appear if you start a second session in parallel: It will load the old version of the persistent history file!
If you need to synchronize the temporary histories of two Bash instances, you need to do this via the persistent history file. There is a command to help you:
history
To flush the current Bash session's temporary history from RAM to the
$HISTFILE
on the disk by appending the new command lines to it, you run:This command gets automatically invoked whenever you exit a Bash session.
To re-read the
$HISTFILE
from the disk and add the new command lines from it to the current Bash session's temporary history which you can use, you run:This command gets automatically invoked whenever you start a Bash session.
Note the leading space in front of both
history
commands. It prevents that thehistory
command itself will appear in the Bash history. If you want it to appear there, just omit the space at the beginning.So to open a new terminal window that has access to all the current history, you need to flush the current temporary history first, and then open a new terminal with a new Bash session:
Again, note the space in the beginning to prevent this command to appear in the histories. If you want it to appear there, omit the space in front of the command.
If you want a short command for that, create a Bash alias:
You could also add a context menu entry to the Gnome-Terminal launcher if you want. Ask for it in a comment if you need it.
To synchronize the histories of two already open terminal windows, first flush the history of the first window, then reload the history file in the second window:
Terminal 1 (source):
Terminal 2 (target):
If you need a two-ways synchronisation, first run the
history -a
commands on all windows, then run thehistory -r
everywhere.More information about the
history
command can be found when you execute