Mail Archives: cygwin/2005/08/10/21:23:50
On Wed, Aug 10, 2005 at 02:47:52PM -0700, L Anderson 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'
>>
>
>Neither of which work if there is a space in the cygdrive prefix; viz a viz:
>
> Prefix Type Flags
>/cyg drive posix path system binmode
Actually yes they will. Did you actually try the above? I did.
>However,
>
>mount -p | sed -nr '2s/([^ ].*) +\S+ +\S+/\1/p'
>
>does the trick.
Here's a little exercise for you. Test your version like this:
bash$ echo "/cygdrive a b c system binmode" | sed -nr '1s/([^ ].*) +\S+ +\S+/\1 <<<HERE/p'
/cygdrive a b c <<<HERE
i.e., trailing spaces, which is what you'd expect from your use of '.*'.
Now try testing my last version:
bash$ echo "/cygdrive a b c system binmode" | sed -nr '1s/(\S) +\S+ +\S+$/\1<<<HERE/p'
/cygdrive a b c<<<HERE
So, the only difference between my version and your version is that
yours includes trailing spaces. I wouldn't call that a benefit.
cgf
--
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 -