[comp.unix.questions] unsetenv TERMCAP in a csh

gandalf@csli.STANFORD.EDU (Juergen Wagner) (05/06/88)

Instead of writing three-line csh scripts of the form
	#! /bin/csh
	unsetenv TERMCAP
	set term = foo
you could use something like
	alias foo "unsetenv TERMCAP; set term = foo"
Yet, even better:
	alias term "unsetenv TERMCAP; set term = \!* ; tset"
which will work for
	term vt100
	term tvi950
	term h19
	term foo
	term bar
(you can guess how it continues). In fact, you can use any terminal
type in /etc/termcap (Great, isn't it?).

Aliases work much better because they are executed in the current 
environment, whereas scripts are run in a new shell. ...and there is
no way to change the parent's environment just bu calling a script.

-- 
Juergen "Gandalf" Wagner,		   gandalf@csli.stanford.edu
Center for the Study of Language and Information (CSLI), Stanford CA

barsam@eros.ame.arizona.edu (Barsam Marasli) (05/07/88)

In article <3780@csli.STANFORD.EDU> gandalf@csli.stanford.edu (Juergen Wagner) writes:
[stuff deleted]
> ...and there is
>no way to change the parent's environment just by calling a script.
>

how about using "source"

(put these in foo)

	unsetenv TERMCAP
	setenv TERM vt100

alias foo "source foo"
foo

------------------------------------------------------------------------
Barsam Marasli                  # Speak slowly, I hear with an accent. #
Internet: eros!barsam@arizona.edu
UUCP    : ...{allegra,ihnp4,cmcl2,hao!noao}!arizona!eros!barsam
Bitnet  : barsam@arizrvax

gandalf@csli.STANFORD.EDU (Juergen Wagner) (05/07/88)

In article <622@amethyst.ma.arizona.edu> eros!barsam@arizona.edu writes:
>...how about using "source"

Sure! But I believe, the original poster didn't talk about source'ing scripts.

--gandalf
-- 
Juergen "Gandalf" Wagner,		   gandalf@csli.stanford.edu
Center for the Study of Language and Information (CSLI), Stanford CA

jfh@rpp386.UUCP (John F. Haugh II) (05/07/88)

In article <3780@csli.STANFORD.EDU> gandalf@csli.stanford.edu (Juergen Wagner) writes:
>Aliases work much better because they are executed in the current 
>environment, whereas scripts are run in a new shell. ...and there is
>no way to change the parent's environment just bu calling a script.
>-- 
>Juergen "Gandalf" Wagner,		   gandalf@csli.stanford.edu

if you need the full function of a shell script you can alias as follows:

alias pushd 'source ~/bin/pushd.rc'

this has the advantage of being an alias, so the command runs in the
current environment, PLUS, (thanks to the source command it works)
you can have a full blown shell script.

- john.
-- 
John F. Haugh II                 | "You see, I want a lot.  Perhaps I want every
River Parishes Programming       | -thing.  The darkness that comes with every
UUCP:   ihnp4!killer!rpp386!jfh  | infinite fall and the shivering blaze of
DOMAIN: jfh@rpp386               | every step up ..." -- Rainer Maria Rilke

terryl@tekcrl.TEK.COM (05/09/88)

In article <3780@csli.STANFORD.EDU+ gandalf@csli.stanford.edu (Juergen Wagner) writes:
+Instead of writing three-line csh scripts of the form
+	#! /bin/csh
+	unsetenv TERMCAP
+	set term = foo
+you could use something like
+	alias foo "unsetenv TERMCAP; set term = foo"

     Yes.....
+Yet, even better:
+	alias term "unsetenv TERMCAP; set term = \!* ; tset"
     Yes.....Yes.....
+which will work for
+	term vt100
+	term tvi950
+	term h19
+	term foo
+	term bar
+(you can guess how it continues). In fact, you can use any terminal
+type in /etc/termcap (Great, isn't it?).
     Yes.....Yes.....Yes.....
+Aliases work much better because they are executed in the current 
+environment, whereas scripts are run in a new shell. ...and there is
+no way to change the parent's environment just bu calling a script.

      One Yes..... & one No.......
      The Yes goes to the comments about aliases, the No to shell scripts
(with a caveat). If you call a shell script by name, then yes, there is no
way to change the parent's environment; IF, however, you say "source <script-
name>" (no quotes) then the parent's environment will be changed (use .
<script-name> if you use the Bourne Shell).

haugj@pigs.UUCP (John F. Haugh II) (05/11/88)

In article <622@amethyst.ma.arizona.edu>, barsam@eros.ame.arizona.edu (Barsam Marasli) writes:
> In article <3780@csli.STANFORD.EDU> gandalf@csli.stanford.edu (Juergen Wagner) writes:
> [stuff deleted]
> > ...and there is
> >no way to change the parent's environment just by calling a script.
> >
> how about using "source"
> ------------------------------------------------------------------------
> Barsam Marasli                  # Speak slowly, I hear with an accent. #

here are a collection of csh scripts to do directory stacks which i hacked
up one day in a fit of laziness.  you need to extract this sharchive into
some reasonable directory (~/bin in my case) and adjust the aliases to suit
your taste.

- john.
----------------------------- sharchive starts here ----------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	popdir
#	pushdir
#	swapdir
# This archive created: Tue May 10 14:24:08 1988
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f 'popdir'
then
	echo shar: "will not over-write existing file 'popdir'"
else
cat << \SHAR_EOF > 'popdir'
if ($#dirstack != 0) then
	cd $dirstack[1]
	shift dirstack
endif
echo '(' $dirstack ')'
SHAR_EOF
fi
if test -f 'pushdir'
then
	echo shar: "will not over-write existing file 'pushdir'"
else
cat << \SHAR_EOF > 'pushdir'
set dirstack = (`pwd` $dirstack)
echo '(' $dirstack ')'
SHAR_EOF
fi
if test -f 'swapdir'
then
	echo shar: "will not over-write existing file 'swapdir'"
else
cat << \SHAR_EOF > 'swapdir'
if ($#dirstack >= 2) then
	set d1 = $dirstack[1]
	set d2 = $dirstack[2]
	shift dirstack
	shift dirstack
	set dirstack = ($d2 $d1 $dirstack)
endif
echo '(' $dirstack ')'
SHAR_EOF
fi
exit 0
#	End of shell archive

--------- add these aliases to your .cshrc after fixing the directories -------

alias pushd 'source ~/bin/pushdir'
alias popd 'source ~/bin/popdir'
alias swapd 'source ~/bin/swapdir'
-- 
 The Beach Bum                                 Big "D" Home for Wayward Hackers
 UUCP: ...!ihnp4!killer!rpp386!jfh                      jfh@rpp386.uucp :DOMAIN

 "You are in a twisty little maze of UUCP connections, all alike" -- fortune

leo@philmds.UUCP (Leo de Wit) (05/19/88)

In article <3780@csli.STANFORD.EDU> gandalf@csli.stanford.edu (Juergen Wagner) writes:
> ...[stuff deleted]...
>Aliases work much better because they are executed in the current 
>environment, whereas scripts are run in a new shell. ...and there is
>no way to change the parent's environment just bu calling a script.

Try the Bourne shell; it has a . command (. script = read commands from script)
so that the parent (the shell) itself reads the commands. But you probably
like the csh better ??!

      Leo (Bourne to be wild).

ljz@fxgrp.UUCP (Lloyd Zusman) (05/21/88)

In article <484@philmds.UUCP> leo@philmds.UUCP (L.J.M. de Wit) writes:
> ...
>Try the Bourne shell; it has a . command (. script = read commands from script)
>so that the parent (the shell) itself reads the commands. But you probably
>like the csh better ??!

And the csh has the 'source' command which does exactly the same thing as
Bourne's "." command.  If you really  love ".", you can do "alias . source"
in csh.


--
  Lloyd Zusman                          UUCP:   ...!ames!fxgrp!ljz
  Master Byte Software              Internet:   ljz%fx.com@ames.arc.nasa.gov
  Los Gatos, California               or try:   fxgrp!ljz@ames.arc.nasa.gov
  "We take things well in hand."

gandalf@csli.STANFORD.EDU (Juergen Wagner) (05/21/88)

In article <484@philmds.UUCP> leo@philmds.UUCP (L.J.M. de Wit) writes:
>...
>Try the Bourne shell; ...
>... But you probably like the csh better ??!

Yes! Definitely, indubitably, unquestionably.

>      Leo (Bourne to be wild).

--
Gandalf (Loving Seashells)
-- 
Juergen "Gandalf" Wagner,		   gandalf@csli.stanford.edu
Center for the Study of Language and Information (CSLI), Stanford CA

rrr@naucse.UUCP (Bob Rose ) (05/24/88)

 Leo de Wit writes:
 > Juergen Wagner writes:
 > > ...[stuff deleted]...
 > >Aliases work much better because they are executed in the current 
 > >environment, whereas scripts are run in a new shell. ...and there is
 > >no way to change the parent's environment just bu calling a script.
 > 
 > Try the Bourne shell; it has a . command (. script = read command script)
 > so that the parent (the shell) itself reads the commands. But you probably
 > like the csh better ??!
 > 
 >       Leo (Bourne to be wild).


 Of course the csh has the `source' command, so there!

        Bob (C shell's csh's by the c shore)



 it's late, and i wanna go home