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.
- Make a file
~/myhistorywith 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 bashto make Bash load history data from
~/myhistory. If your default shell is
bashthen you can lose the
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.