Can I start xterm
with a custom bash history including a list of predefined commands? So that I can run several xterm
, where each instance has his own history.
1 Answer
- Make a file
~/myhistory
with the commands you want in the history, one per line chmod a-w ~/myhistory
, so that Bash won't try to change it. If you want the commands the user enters to be written back (to that same file), skip this step.HISTFILE=~/myhistory xterm -e bash
to make Bash load history data from~/myhistory
. If your default shell isbash
then you can lose the-e bash
.
Within the shell the command history will be what you wrote in the file, accessible through the up arrow, history expansion, the fc
command, or any other way you get to the history.
If you can't make a real file, this fairly-hacky workaround will work as well:
HISTFILE=<(printf '%s\n' command1 "second 'command here'" 3rd) xterm -e bash
This uses process substitution to generate a file-like entity for the shell to read from, with the output of the printf
command as the contents. This printf
will print out each of the arguments, one per line. You'll have to quote things carefully to make sure that the commands as output are in the format you need.
-
Does this also work, if I want to start several
xterm
, where each has his own history file? May 12, 2017 at 5:16 -
-
So I can set (override) the environment variable
HISTFILE
for eachbash
instance when they run simultaneously without loosing the link between onebash
instance and their history file? May 12, 2017 at 5:27 -