This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
Re: How to extract suffix from a filename?
- To: "malcolm.boekhoff" <malcolm dot boekhoff at actfs dot co dot uk>
- Subject: Re: How to extract suffix from a filename?
- From: "Ehud Karni" <ehud at unix dot simonwiesel dot co dot il>
- Date: Tue, 26 Jun 2001 15:01:07 +0300
- CC: cygwin at cygwin dot com, "Michael A. Chase" <mchase at ix dot netcom dot com>
- Organization: Simon & Wiesel Insurance agency
- References: <20010626103817.A221@BOEKHOFF_M>
- Reply-to: ehud at unix dot simonwiesel dot co dot il
On Tue, 26 Jun 2001 10:38:17 +0100, malcolm.boekhoff <malcolm.boekhoff@actfs.co.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@unix.simonwiesel.co.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/