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



Christopher Faylor wrote:


On Wed, Aug 10, 2005 at 02:36:16PM -0400, 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'



This is shorter:


mount -p | sed -nr '2s/([^ ]) +\S+ +\S+$/\1/p'

cgf




Or you can do it the long, slow wasteful way, which us dullards are required
to use, so we can figure out why it broke yet again.

#!/bin/bash
let c=0;
# get the number of fields
for i in `mount -p | tail -1`; do let c=$c+1; done

# if number of fields is greater than 3 because mount point has a space, add them
CUT_FIELDS="--fields=1"
let i=3;
while [ $i -lt $c ]
do
CUT_FIELDS=$CUT_FIELDS,$i
let i=$i+1
done


# get the fields
mount -p | tail -1 | /usr/bin/cut --delimiter=" " $CUT_FIELDS



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