Question

when I execute this script the terminals are opening and immediately closing, so I can't see the result.

Nothing that I know helps.

I'm using SunOS 5.9 and it's not my fault))

#!/bin/bash

if [ -z "$1" ]; then 
echo "enter command"
fi

if [ -z "$2" ]; then 
echo "enter command"
fi

if [ -z "$3" ]; then 
echo "enter command"
fi

xterm -e $1 | wait & 

xterm -e $2 | wait & 

xterm -e $3 | wait & 
Was it helpful?

Solution

Assuming that you want to see what the command produced even if it failed, replace your commands with:

xterm -xrm '*hold: true' -e $1 &   # this is to keep xterm from closing
pid1=$!  # this is to save the pid, in case you want to close it
disown   # this is to prevent the finishing shell from closing the xterm

Alternatively, if the xterm does not support -xrm option:

CMD="$1" xterm -e $SHELL -c '$SHELL -c "$CMD"; read'

The two shells are to protect from syntax errors in the command, to keep the xterm open even in this case.

OTHER TIPS

The -hold option was added to XFree86 xterm in 1999 (patch 116). However, Sun continued to provide the "openwin" binary of xterm until Solaris 11 in 2011 (see the xterm FAQ Why can't I use the pageup/pagedown keys?). Until that point, Sun provided modern xterm on the freeware CDROM.

The usual recommendation for providing a "hold" feature involved a "read" command after the desired command. That assumes that the command to be executed runs in a shell. If one wants to run vi, the suggested fix does not work because the alternate screen may be involved. Also, it relies on having $SHELL set (and does not work for some, such as tcsh -- but does work for bash).

Here is an improved script which solves those problems:

#!/bin/bash
export SHELL=/bin/bash
while [ $# != 0 ]
do
    CMD="$1" \
    xterm -xrm '*titeInhibit:true' -e $SHELL -c '$SHELL -c "$CMD"; read'
    shift 1
done

All versions of xterm support the -xrm switch (it comes for free with Xt, the X Toolkit library).

The explicit titeInhibit resource addresses a problem with running full-screen applications such as vi. The terminal description provided for xterm in Solaris 11 uses the alternate screen for full-screen applications. This is discussed in the xterm FAQ Why doesn't the screen clear when running vi?. Without the resource setting, if one ran the script to vi several files, the screen would be cleared after exiting vi and while waiting for the user to press Enter to close the window. On other systems where this behavior is not the default, the xterm- or ncurses-sources have been patched to reflect packager's preferences. Likewise, the terminfo source for Solaris 9 had been patched. Nonetheless, failing to handle a commonly used behavior of xterm would be a problem.

Even with Solaris 9, for example, many users relied on ncurses to provide a workable color terminal description. Solaris (as noted in the xterm FAQ What $TERM should I use?) provided xtermc, but its function-keys were completely different from the actual xterm, making it a poor choice. The Sun freeware cdrom's terminfo (from ncurses) was not patched; people using that terminal database got the expected behavior with the alternate screen.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top