delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/10/02/15:05:45

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-Id: <5.1.0.14.2.20021002120019.02bc1eb0@pop3.cris.com>
X-Sender: rrschulz AT pop3 DOT cris DOT com
Date: Wed, 02 Oct 2002 12:06:08 -0700
To: cygwin AT cygwin DOT com
From: Randall R Schulz <rrschulz AT cris DOT com>
Subject: Re: Bash script and export CLASSPATH
In-Reply-To: <20021002185606.79218.qmail@web40201.mail.yahoo.com>
Mime-Version: 1.0

Brian,

No, it's not odd. It's correct.

This is a generic thing about how environment variables work and is in no 
way specific to the CLASSPATH variable (or any other PATH or pre-defined or 
built-in variable) nor is this specific or peculiar to Cygwin.

When you execute a shell script such as the one you showed, a sub-process 
is created to run that script. Environment variables are inherited by all 
new child sub-processes. However, variables defined or changed in a 
sub-process are never passed back to the parent process that created the 
sub-process.

The usual way to accomplish the sort of variable-setting you (appear to) 
want is to use the "source" command (or it's synonym, "."). This shell 
built-in causes the commands in the named script to be executed by the same 
shell that executed the "." or "source" command. Arguments are not passed 
in this case. You need to be a little careful with that variety of script. 
For example, invoking the "exit" command will cause your interactive shell 
to terminate.

Good luck.

Randall Schulz
Mountain View, CA USA


At 11:56 2002-10-02, Brian Rowe wrote:
>Hello,
>If I export CLASSPATH=blah on the command line it
>works fine.  If I write a shell program that sets the
>CLASSPATH it won't set it!  When I echo the value its
>right from the script, but when its done the CLASSPATH
>is not set.  Any ideas on why this wouldn't work?
>
>#!/bin/sh
>export CLASSPATH="C:\jdk\lib\tools.jar"
>
>Run that, then check echo $CLASSPATH at the command
>line and CLASSPATH is the same. Odd?


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019