1

I want to run a script called tuxsay that combines fortune and cowsay to have tux say some words of wisdom. I made an alias in by .bash_aliases calling it tuxsay and executing the script

FORTUNE= $(fortune)
cowsay -f tux $FORTUNE

I then have a script that will spawn a new terminal and I want it to output the results of my first script then allow me to work in the terminal, something like

xterm -e "tuxsay&"

So how can I spawn a new terminal use cowsay then allow me to work in it?

Specifics: I have a startup script that will spawn applications that I typically use, and I want it to spawn a terminal that runs my tuxsay script then allows me to work. I am on Ubuntu 12.04 LTS and am running dwm 6.0

Zachary Alfakir
  • 83
  • 1
  • 11

1 Answers1

2

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.

Community
  • 1
  • 1
Digital Trauma
  • 15,475
  • 3
  • 51
  • 83