According to the bash
manual, ~/.bashrc
is used for interactive shells. xterm runs a shell, so perhaps your "does not work" causes a chain of xterm's.
The xterm program sets these environment variables which are useful for scripting: XTERM_VERSION
and XTERM_SHELL
. In your ~/.bashrc
file, you could use the former to run the xterm -ls
once only:
if [[ -z "$XTERM_VERSION" ]]
then
xterm -hold -e ls &
fi
which seems to be what you are asking for:
- it would run an xterm if not run from an existing xterm
- it prevents the xterm from closing when the
ls
is done.
A more useful-seeming way of showing an ls
on shell startup would be to run ls
in each shell as it is started (for that case, you do not need run a separate xterm
). Again, you can use environment variables to do this once (in case you run bash
to make a subshell):
if [[ -z "$XTERM_ONCE" ]]
then
export XTERM_ONCE=$(date)
ls
fi