delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/06/26/10:46:29

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Message-Id: <5.1.0.14.2.20010626072853.026e9df8@pop3.cris.com>
X-Sender: rrschulz AT pop3 DOT cris DOT com
X-Mailer: QUALCOMM Windows Eudora Version 5.1
Date: Tue, 26 Jun 2001 07:44:33 -0700
To: "malcolm.boekhoff" <malcolm DOT boekhoff AT actfs DOT co DOT uk>,
Cygwin News Group <cygwin AT sources DOT redhat DOT com>
From: Randall R Schulz <rrschulz AT cris DOT com>
Subject: Re: How to extract suffix from a filename?
In-Reply-To: <20010626103817.A221@BOEKHOFF_M>
Mime-Version: 1.0

Malcolm,

I know nothing of Mutt nor what interpretation is placed on the contents of 
a ".mailcap" file, but your example looks like shell code to me, so as a 
fond BASH user I'll direct you to its feature allowing string manipulations 
upon the value of variables as they are being expanded.

% FULLNAME="/dir/base.suf1.suf2"
% DIR="${FULLNAME%/*}"
% FILE="${FULLNAME##*/}"
% MAXBASE="${FILE%.*}"
% MINBASE="${FILE%%.*}"
% MAXSUF="${FILE#*.}"
% MINSUF="${FILE##*.}"
% echo $DIR $FILE $MAXBASE $MINBASE $MAXSUF $MINSUF
/dir base.suf1.suf2 base.suf1 base suf1.suf2 suf2

The patterns are matched using shell "glob" pattern matching (as in file 
name matching: ?, * and [...] patterns), not regular expression matching. 
The MAX/MIN pairs accounts for the possibility of multiple periods in the 
FILE name.

See section 3.10 of the BASH manual (that's an old version of the manual, 
so it may have been displaced to an adjacent section in later editions).

There is also a generalized substitute mode of expansion. It's documented 
in the same place.

Randall Schulz
Mountain View, CA USA


At 02:38 2001-06-26, malcolm.boekhoff wrote:
>Okay, it's a silly question - how can I extract the suffix from a file
>name (I know I can use "basename" and "dirname" to get the file and
>directory components)?
>
>Read the rest of this mail message if you can be bothered.
>
>I want to do this because my script executed from my .mailcap file in
>mutt spawns off internet explorer or word or whatever other GUI thing is
>required to read attachments like ".doc" and ".pps", etc. and I can keep
>reading mail in mutt asynchronously.  To make this work I need to copy
>the temporary file created by mutt and sometimes maybe this needs to end
>in ".doc" and I would rather not hard-code the suffix in the script,
>because, maybe somtimes, say for image/* mimetype, the suffix could be
>".jpg" or ".tiff", etc. and maybe the invocation of IE5 requires the
>target to end in ".jpg" or ".tiff" and it probably isn't right for me to
>copy the "source.tiff" to "target.jpg" and start IE5 on the target.
>Maybe.
>
>I would like to use the suffix on the file supplied by mutt here,
>instead of hard coding it.                                   |
>                                                              |
>                                                              |
>                                                              |
>                                             +----------------+
>..                                         |
>             application/vnd.ms-excel)       v
>                 TMPFILE=`mktemp $TEMPLATE`.xls
>                 COMMAND="/c/program\ files/microsoft\ office/office\
>/excel \"`cygpath -a -w \"$TMPFILE\"`\"&"
>             ;;
>..
>cp -fp "$SRCFILE" "$TMPFILE"
>eval $COMMAND
>
>***********************************************************************
>This message has been checked for all known viruses by the
>E-mail Virus Protection service, powered by MessageLabs.
>***********************************************************************
>
>--
>Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>Bug reporting:         http://cygwin.com/bugs.html
>Documentation:         http://cygwin.com/docs.html
>FAQ:                   http://cygwin.com/faq/


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019