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 Message-ID: <42FA60C9.90201@alltel.net> Date: Wed, 10 Aug 2005 15:17:13 -0500 From: Ken Dibble User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: Programatically finding value of "cygdrive" prefix References: <42FA4604 DOT 8000507 AT tlinx DOT org> <20050810183616 DOT GA5892 AT trixie DOT casa DOT cgf DOT cx> <20050810184119 DOT GA6155 AT trixie DOT casa DOT cgf DOT cx> <42FA4EC2 DOT 3000504 AT alltel DOT net> <20050810194024 DOT GC6294 AT trixie DOT casa DOT cgf DOT cx> In-Reply-To: <20050810194024.GC6294@trixie.casa.cgf.cx> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Christopher Faylor wrote: >On Wed, Aug 10, 2005 at 02:00:18PM -0500, Ken Dibble wrote: > > >>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' >>> >>> >>> >>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 >> >> > >Personally, if something breaks, I'd rather look at one line than >eighteen. I can't imagine why anyone would find the above an acceptable >solution when it's possible to do it all with one line. And, the above >doesn't handle imbedded spaces. > >Btw, a further simplification: > >mount -p | sed -nr '2s/(\S) +\S+ +\S+$/\1/p' > >cgf > > You are right, the shell script that I wrote does not address the issue it was intended for. I apologize for any inconvienence this caused anyone. As well, I apologize for not spending enought time using sed for your sed scripts to mean anything to me. Ken -- 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/