How do I run a command when starting xterm?

How can I run the command when starting xterm, i.e. when starting the terminal xterm the command has already been executed?

I modified the .bashrc file to add this line:

xterm "ls"

But that won't work.

Please suggest what should I do to achieve this.

Thank.

+3


source to share


2 answers


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

      

+1


source


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).

http://linux.die.net/man/1/rxvt

0


source







All Articles