delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/08/16/17:11:13

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
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
Date: Tue, 16 Aug 2005 17:10:25 -0400 (EDT)
From: Igor Pechtchanski <pechtcha AT cs DOT nyu DOT edu>
Reply-To: cygwin AT cygwin DOT com
To: Hannu E K Nevalainen <_garbage_collector_ AT telia DOT com>
cc: cygwin AT cygwin DOT com
Subject: Re: Programatically finding value of "cygdrive" prefix
In-Reply-To: <1124222681.29974.37.camel@p450>
Message-ID: <Pine.GSO.4.61.0508161649420.9560@slinky.cs.nyu.edu>
References: <42FA4604 DOT 8000507 AT tlinx DOT org> <20050810183616 DOT GA5892 AT trixie DOT casa DOT cgf DOT cx> <Pine DOT GSO DOT 4 DOT 61 DOT 0508152130380 DOT 9560 AT slinky DOT cs DOT nyu DOT edu> <1124222681 DOT 29974 DOT 37 DOT camel AT p450>
MIME-Version: 1.0

On Tue, 16 Aug 2005, Hannu E K Nevalainen wrote:

> On Mon, 2005-08-15 at 21:43 -0400, Igor Pechtchanski wrote:
> > On Wed, 10 Aug 2005, Christopher Faylor wrote:
> >
> > > On Wed, Aug 10, 2005 at 11:23:00AM -0700, Linda W wrote:
> > > >Is there a way to find out in a bash script the cygdrive prefix?
> > > >I thought something simple like
> > > >   mount -p|tail -1|cut -f1
> > > >but that incorrectly assumed the fields were tab delimited.
> > > >Since there can be spaces in the cygdrive prefix, I can't
> > > >use space a delimiter, example:
> > > ># mount -p
> > > >Prefix              Type         Flags
> > > >/cyg drive posix path  system       binmode
> > > >----
> > >
> > > There may be a simpler way to do it, but this seems to work:
> > >
> > > mount -p | sed -n '2s/\([^ ]\)  *[^ ][^ ]*  *[^ ][^ ]*$/\1/p'
> >
> > The main question is: *why* would one want to programmatically find out
> > the cygdrive prefix?

Hi, Hannu...

> You're making assumptions without insight, Igor. Please, don't assume!
> Be open minded and allow to extract the information in an easily
> accessible manner - PLEASE.

Huh?  I wasn't making any assumptions, I was asking for the actual problem
that programmatically accessing the cygdrive prefix was supposed to solve.
Knowing the intended usage would make it easier to write a custom
accessor, as opposed to something generic.

> In general, having a setting be "hidden" in the manner that the cygdrive
> prefix is - is a bad idea. Simply because you never know what other ppl
> might come up with, if it IS accessible.
>
> Allowing RE-Reading the value of a parameter, that can be set, should
> IMO never be restricted, unless maybe the restricting is based on
> security... (passwords comes to mind)
>
> Check my local example "cygdrive" use below. Not perfect, but works - as
> it is - in my very static cygwin setup (e.g. has problems w spaces under
> certain conditions, a condition NOT present on my computers; I'm rabid
> on this)

The whole idea was to address cygdrive prefixes that may have spaces.

> > If all you want is access '/cygdrive/c' via a POSIX path, wouldn't
> > "cygpath -u c:" do the right thing?  In fact, barring special mounts,
> > "cygpath -u c:|sed 's#/c$##'" should do what the OP asked.
>
> Are you sure there is a C: drive on every Windows computer, I wouldn't
> wager on that.

There may not be a C: drive, but "cygpath -u c:" will do the right thing
-- try it with a drive you don't have.

> > Alternatively, one could actually use the quotes that "mount -m"
> > produces, via something like
> >
> > mount -m | grep -- --change-cygdrive-prefix | \
> >   xargs bash -c 'while [ $# != 1 ]; do shift; done; echo "$@"' --
>
> IMO, something like
> $ mount -m | grep 'cygdrive-prefix' | sed -rne 's/.*"(.*)".*/\1/p'
>
> should work ; UNTESTED (I'm on Linux right now)

This won't always work.  The cygdrive prefix may not be the only thing in
quotes.

> ---8<--- example use ---
> [snip]
> [henk AT p450 scripts]$ cat cygdrives
> #!/bin/bash
> # show paths to all mounted DOS/WINDOWS devices.
> mount | grep -E "$(cygprefix)[a-z] " | cut -d" " -f3

Hmm, why not simply 'echo "$(cygprefix)[a-z]"'?

> [henk AT p450 scripts]$ cat cygprefix
> #!/bin/bash
> # grep out the cygwin prefix for DOS/WINDOWS devices
>
> mount -p |
> tail -1 |
> (
>   read p z;
>   if [ ! "${p: -1}" == "/" ] ;then
>     p="$p/";
>   fi;
>   echo "$p"
> )

Again, not space-friendly.  And much longer than most scripts proposed in
this thread.
	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!

If there's any real truth it's that the entire multidimensional infinity
of the Universe is almost certainly being run by a bunch of maniacs. /DA

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