Why not just add your command to your .bashrc
file? Then it will be run every time a new interactive shell is started. You can test if the $TERM
variable contains "xterm", and make your output conditional upon that. e.g. add the following line to the end of .bashrc
:
[[ "$TERM" =~ xterm ]] && tuxsay
Update
While I think the above is still probably the most useful general answer, I noticed a few more things:
tuxsay
is a bash alias. bash aliases are only understood within bash itself, but when you pass a command to xterm -e
, that command is executed directly by the xterm without any bash involvement. The system won't be able to find and execute a file called "tuxsay" and will fail.
If executed from bash, the &
character will put tuxsay command (alias) in the background, but this doesn't really help here. What you need is a new shell to start up once tuxsay is done.
Be careful with .bash_aliases
. I noticed on my Redhat-based system that aliases placed in this file were not working, because .bash_aliases
file is not sourced in. (My Bash aliases don't work) So it looks like .bash_aliases
is sourced by default from Ubuntu-based systems, but no guarantees for others.
With the above in mind, if you definitely want tuxsay to run on a per-xterm basis – i.e. you want to specify this on the xterm command line – you could do the following one-liner:
xterm -e 'cowsay -f tux $(fortune); bash'
This passes the compound command cowsay -f tux $(fortune); bash
to xterm. This compound command consists of two commands: first do the cowsay
thing, then start bash.
You could also put these two commands in a shell script and pass the shell-script to xterm.