delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/06/26/08:19:42

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
Date: Tue, 26 Jun 2001 15:01:07 +0300
Message-Id: <200106261201.PAA29489@linux.>
From: "Ehud Karni" <ehud AT unix DOT simonwiesel DOT co DOT il>
To: "malcolm.boekhoff" <malcolm DOT boekhoff AT actfs DOT co DOT uk>
Subject: Re: How to extract suffix from a filename?
CC: cygwin AT cygwin DOT com, "Michael A. Chase" <mchase AT ix DOT netcom DOT com>
In-reply-to: <20010626103817.A221@BOEKHOFF_M> (message from malcolm.boekhoff
on Tue, 26 Jun 2001 10:38:17 +0100)
Organization: Simon & Wiesel Insurance agency
Reply-to: ehud AT unix DOT simonwiesel DOT co DOT il
References: <20010626103817 DOT A221 AT BOEKHOFF_M>
X-Mailer: Emacs 20.7.1 rmail (send-msg 1.104)
MIME-Version: 1.0

On Tue, 26 Jun 2001 10:38:17 +0100, malcolm.boekhoff <malcolm DOT boekhoff AT actfs DOT co DOT uk> 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)?

if the suffix is of fixed length (usually 3 chars) then (in bash) the
following will do: SUF=`echo <name> | tail -4c`

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

Below are an example from my mailcap that does something like that and
the bash scripts used.

Ehud.


# my change to xv - to save in the original name
image/*; ek-xv %s %{name}

# special case for SW fax files - *.SWD/*.swd
application/octet-stream; ek-xv %s %{name} ;       \
       test=swdchk.sh %{name} ;


The 2 scripts used above (you might want to change the /bin/sh to
/bin/bash, on my Linux and Cygwin /bin/sh=/bin/bash):


#! /bin/sh -e
# script for saving and showing images in mail decoding
# --------------------------------------------------

exec 2>/dev/null                           # no stderr !

IMG="$1"                                   # name of image to show
ONM="$2"                                   # original name
DIR=`dirname $IMG`                         # dir name of image
BNM=`basename $IMG`                        # base name of image
cd $DIR                                    # work in saved dir

if [ "$ONM" = "" ] ; then
    ONM="$BNM"                             # no 2nd arg - use basename
else
    mv "$BNM" "$ONM"                       # change to user original name
fi

case "$ONM" in
   *.SWD | *.swd | *.DCX | *.dcx )         # FAX file
       NMO=`echo "----$ONM" | cut -c5-${#ONM}` # name without extension
       dcx2pcxs "$ONM" ${NMO}_             # break into pcx's
       xview -global -zoom 40 ${NMO}*.pcx > /dev/null &    # view it in BG
       exit 0 ;;                           # exit this script
esac

set +e
xview "$ONM" > /dev/null &                 # view it in BG (no details)

################################### ek-xv ###################################

#! /bin/sh -e
# --------------------------------------------------

case "$1" in                           # attachment file name
   *.SWD | *.swd | *.DCX | *.dcx )     # FAX file
       exit 0 ;;                       # exit this script
   * ) exit 1 ;;                       # NOT fax/swd
esac

############################## swdchk.sh ##############################


--
 Ehud Karni     Mivtach - Simon  Insurance   /"\
 Tel: +972-3-6212-757 Fax: +972-3-6292-544   \ /  ASCII Ribbon Campaign
 (USA) Fax and  voice  mail: 1-815-5509341    X   Against  HTML  Mail
     Better     Safe     Than     Sorry      / \
     mailto:ehud AT unix DOT simonwiesel DOT co DOT il    http://www.simonwiesel.co.il

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