Date: Tue, 25 May 1999 00:14:14 +0200 From: Juergen Nickelsen <jnickelsen@acm.org> To: "Alexey V.Vinogradov" <alexv@Sun.Farlep.Net> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: about stty and TERM variable Message-ID: <829909.3136580054@ockholm.jn.berlin.snafu.de> In-Reply-To: <199905241116.OAA21115@Sun.Farlep.Net>
next in thread | previous in thread | raw e-mail | index | archive | help
--On Mon, 24. Mai 1999 14:16 +0300 "Alexey V.Vinogradov"
<alexv@Sun.Farlep.Net> wrote:
> who i can change TERM variable for stty?
> i do in sh shell scripts TERM=vt100; export TERM
> and have after run:
> tput: no terminal tipe specified and no TERM enviromental variable
If you set or unset an environment variable of a process (usually the
shell), the change will be inherited to the child processes, but not to
the parent. Changing environment variables in a shell script will thus
effect the shell script and the programs started by the script, but not
your login shell (which, I assume, has started the script).
To change an environment variable for your login shell (or any other
interactive shell), set it either by hand or in a script that is
sourced by this shell (without starting a subprocess), or in a shell
function or alias.
For instance, I have a shell function (I use bash) "path" to change the
PATH variable. It calls a perl script, which does things to PATH (show
the PATH, add or delete components, or even call a text editor on
PATH). The script then writes the new PATH setting to stdout, which is
evaluated by the shell function. This works, because a shell function
runs in the process context of the shell which called the function.
Oh well, I think this still sounds complicated. Let me summarize:
- *Calling* a script (or any other program) to set an environment
variable in your current shell does *not* work.
- *Sourcing* a script (which is then executed by your current shell)
works. ("." with sh, ksh, zsh, bash; "source" with csh, tcsh.)
- Using a shell function or alias works.
E. g. to add a directory in front of the path you could use a shell
function like
adpath () { [ "$1" != "" ] && PATH=$1:$PATH ; }
for sh, ksh, zsh, bash; or for csh and tcsh an alias like
alias addpath 'set path = ( \!* $path )'
Greetings, Juergen.
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?829909.3136580054>
