This is the mail archive of the cygwin 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: Programatically finding value of "cygdrive" prefix


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@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@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@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.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/


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