How do I run a command when starting xterm?
bash
~/.bashrc
Used for interactive shells as instructed . xterm starts up a shell, so it may be that your "not working" is calling xterm's chain.
The xterm program sets these environment variables , which are useful for scripting: XTERM_VERSION
and XTERM_SHELL
. In your file, ~/.bashrc
you can use the first to run only xterm -ls
:
if [[ -z "$XTERM_VERSION" ]]
then
xterm -hold -e ls &
fi
which seems to be what you are asking for:
- it starts the xterm if not started from an existing xterm
- it prevents the xterm from being closed when executed
ls
.
A more useful way of showing ls
on shell startup would be to run ls
in each shell as it starts (in which case you don't need to start a separate one xterm
). Again, you can use environment variables for this one time (in case you run bash
to make a subshell):
if [[ -z "$XTERM_ONCE" ]]
then
export XTERM_ONCE=$(date)
ls
fi
source to share
I am using this:
-e /bin/bash -login
-e command [arguments]
Run the command with its command line arguments in the rxvt window; also sets the window title and icon name as the base name of the program execution if neither (-T) or -n is specified on the command line. If this parameter is used, it must be the last one on the command line. If the -e parameter is absent, then the default is to start the program specified by the SHELL environment variable or, otherwise, w (1).
source to share