delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/12/06/22:58:14

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
X-Authentication-Warning: slinky.cs.nyu.edu: pechtcha owned process doing -bs
Date: Sat, 6 Dec 2003 22:57:54 -0500 (EST)
From: Igor Pechtchanski <pechtcha AT cs DOT nyu DOT edu>
Reply-To: cygwin AT cygwin DOT com
To: svartsjel AT gmx DOT net
cc: cygwin AT cygwin DOT com
Subject: Re: bash loop troubles
In-Reply-To: <20389.1070758668@www55.gmx.net>
Message-ID: <Pine.GSO.4.56.0312062254100.16580@slinky.cs.nyu.edu>
References: <20389 DOT 1070758668 AT www55 DOT gmx DOT net>
Importance: Normal
MIME-Version: 1.0

On Sun, 7 Dec 2003 svartsjel AT gmx DOT net wrote:

> Hi,
>
> I tried to run the following bash script:
>
> for drive in a b c d e f g h i j k l m n o p q r s t u v w x y z
> do
>    alias ${drive}:="cd /cygdrive/${drive}"
> done
>
> I guess, the syntax for the loop is okay, if I replace the alias line with a
> simple echo command:
>
> echo $drive
>
> I get
>
> a
> b
> ...
>
> and so on.
>
> Doing the following (both at the prompt and within a bash script):
>
> drive='c'; alias $drive:="cd /cygdrive/$drive"
>
> will lead to the alias as expected. Merely inside the loop it just doesn't
> seem to work.
> Any hints?
>
> Thanks in advance,
> Michael

Michael,

If I guessed correctly at what you're trying to accomplish (create aliases
*in your current shell* to duplicate cmd.exe's syntax for switching
drives; not at all obvious from the above description), and how you're
doing it (from the inside of a bash *script*), you seem to have forgotten
that scripts run in a subshell, and aliases created within that subshell
will not get propagated back to the parent shell.  In other words, it's
not the loop, it's the script.  You will need to 'source' (or '.') the
script file for this to work.  FWIW, the above WFM.
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha AT cs DOT nyu DOT edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor AT watson DOT ibm DOT com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"I have since come to realize that being between your mentor and his route
to the bathroom is a major career booster."  -- Patrick Naughton

--
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