[Gllug] Why does this script not work?

Pete Ryland pdr at pdr.cx
Sun Dec 16 00:03:27 UTC 2001


On Sat, Dec 15, 2001 at 09:22:31PM +0000, Nix wrote:
> On Tue, 11 Dec 2001, tet at accucard.com muttered drunkenly:
> > 
> >>> append :
> >>> exec /bin/bash
> >>> 
> >>> is one option.
> >>
> >>This would give you a new subshell every time you ran that script; if it
> >>was used anything like `cd', you'd end up with about a hundred million
> >>subshells to exit back out of.
> > 
> > Errr.... no. That's what the "exec" is for. But there are other reasons
> 
> Errr... yes. It's already forked a subshell to handle the shell script
> (assuming the script was run, rather than sourced), so despite the
> replacement via `exec', you'll get one extra subshell per invocation.
> 
> > Tet (confused as to why typing "cd .." is so hard anyway...)
> 
> ... and why writing shell functions to do the changing rather than shell
> scripts is so hard...

Maybe what you want to do can be achieved using the PROMPT_COMMAND env var
instead (with bash only afaik, although I'm sure zsh has something better -
it always does! :).

For example, I have in my .bashrc, something close to the following:

    function set_title() {
      if [ x$1 != x--keep ]; then
        SET_TITLE_EXTRA="$*"
      fi
      if [ -z "$SET_TITLE_EXTRA" ]; then
        NAME="$USER@$HOSTNAME:$PWD"
      else
        NAME="$USER@$HOSTNAME:$PWD ($SET_TITLE_EXTRA)"
      fi
      echo -n 
    }
    case $TERM in
    xterm*)
        PROMPT_COMMAND='set_title --keep'
        ;;
    *)
        ;;
    esac

This allows me to set the title of my xterm with the current username, host
and working directory and even purpose (purpose set using the set_title
function) of each window.

Pete
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 240 bytes
Desc: not available
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20011216/d2e4eb82/attachment.pgp>


More information about the GLLUG mailing list