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 DOT post AT talk DOT nabble DOT com> From: "Buchbinder, Barry \(NIH/NIAID\) [E]" To: "SCHLING" , X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT 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/