This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: bash loop troubles

On Sun, 7 Dec 2003 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


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.
      |\      _,,,---,,_
ZZZzz /,`.-'`'    -.  ;-;;,_
     |,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:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]