delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/05/03/12:31:50

X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
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 DOT post AT talk DOT nabble DOT com>
From: "Buchbinder, Barry \(NIH/NIAID\) [E]" <BBuchbinder AT niaid DOT nih DOT gov>
To: "SCHLING" <schling AT mail DOT telepac DOT pt>, <cygwin AT cygwin DOT com>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/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
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/


- Raw text -


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