Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm 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 Subject: Re: Programatically finding value of "cygdrive" prefix From: Hannu E K Nevalainen <_garbage_collector_ AT telia DOT com> To: cygwin AT cygwin DOT com In-Reply-To: References: <42FA4604 DOT 8000507 AT tlinx DOT org> <20050810183616 DOT GA5892 AT trixie DOT casa DOT cgf DOT cx> Content-Type: text/plain Date: Tue, 16 Aug 2005 22:04:40 +0200 Message-Id: <1124222681.29974.37.camel@p450> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes 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? 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. 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) NOTE: A digital camera shows up as an USB drive, i.e. a DOS drive -> e.g. /cygdrive/ - and is available so long as the camera stays ON (it eventually WILL go OFF after last use, just as your screen blanker! Depending on how you've set it or use it.) > 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. > 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) ---8<--- example use --- [henk AT p450 scripts]$ cat digicam #!/bin/bash # (C) Copyright 2003-10-29 by Hannu E K Nevalainen, Mariefred, Sweden # With the exception of the copyright, this script is # free with the restrictions set by the fsf.org GPL. # Prerequisites: # MANY digital still image cameras connect to a host computer # via e.g. USB, and thus show up as one extra mass storage device. # This device contains a _standardized_ directory tree. One of the # facts is that there is a DCIM folder in the root. # The DCIM folder contains at least yet one level of folders # which in turn will contain the images. These can be either # *.JPG *.MOV and presumably *.TIF (I'm not aware of others) # # The script first finds out currently mounted DOS/WINDOWS devices. # Then loops through these looking for the root DCIM-folder... # those that contain the folder will have their cygwin path printed. for i in $(cygdrives) ;do if [ -d $i/DCIM ] ;then echo $i; fi; done [henk AT p450 scripts]$ cat cygdrives #!/bin/bash # (C) 2003-10-29 by Hannu E K Nevalainen, Mariefred, Sweden # # show paths to all mounted DOS/WINDOWS devices. mount | grep -E "$(cygprefix)[a-z] " | cut -d" " -f3 [henk AT p450 scripts]$ cat cygprefix #!/bin/bash # (C) 2003-10-29 by Hannu E K Nevalainen, Mariefred, Sweden # # 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" ) [henk AT p450 scripts]$ /Hannu E K Nevalainen -- 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/