X-Spam-Check-By: sourceware.org
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain; 	charset="us-ascii"
Subject: RE: CD doesn't work in script
Date: Thu, 3 May 2007 12:31:19 -0400
Message-ID: <31DDB7BE4BF41D4888D41709C476B657068AAF35@NIHCESMLBX5.nih.gov>
In-Reply-To: <10307440.post@talk.nabble.com>
References: <10307440.post@talk.nabble.com>
From: "Buchbinder, Barry \(NIH/NIAID\) [E]" <BBuchbinder@niaid.nih.gov>
To: "SCHLING" <schling@mail.telepac.pt>, <cygwin@cygwin.com>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
Precedence: bulk
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie.com@cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id l43GVZ7b013183

SCHLING wrote on Thursday, May 03, 2007 12:18 PM:
> 
> I have successfully installed Cygwin on XP SP2, and would like to run
> a script which includes a change directory command (cd \etc.) 
> 
> All the other lines of the script work except the one with cd. The
> same line works when input by hand. 
> 
> Searching on the net I found that line endings could be critical (Lf
> instead of CrLf) and ran the script through d2u. Still no success. 
> 
> Curiously, if the script tries a cd with a non-existing directory, I
> get a warning. Otherwise, the script runs without any problems, but
> the active directory does not change.  
> 
> Don't know what to do next...
> 
> Any help appreciated
> 
> Robert

A script that starts with a #!/bin/sh or the like runs in a sub-shell,
i.e., its own process.  (I'm assuming that what you are doing.)  A "cd"
in the script changes the working directory of the sub-shell, not its
parent, the shell from which the sub-shell was launched.  When the
script exits, one finds oneself in the original directory because the
command (parent) shell has not done a "cd".

What it seems you want to do is to *source* the script.  In bash you can
do it at least two ways:
	$ . script
	$ source script

For convenience, you can set up a alias so that you don't have to
remember to type "." or "source".
	alias script='. /path/script'
Y do not need to include the path if the names of the alias and script
are different.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


