[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] The best way to trim trailing .tiff or .tif?
From: |
Eric Blake |
Subject: |
Re: [Help-bash] The best way to trim trailing .tiff or .tif? |
Date: |
Fri, 05 Oct 2012 08:31:21 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120911 Thunderbird/15.0.1 |
On 10/05/2012 08:26 AM, Eric Blake wrote:
>
> Your use of 'function', 'local', and '[[' agree with your choice of
> #!/bin/bash, in that your script is definitely non-POSIX; extended
> globbing is also a bash extension, and therefore right in line with your
> intent of being bash-only. However, if you want to scrub things so that
> you can be portable to POSIX sh, I think the most concise you can get is:
>
> cmd () {
> case $1 in
> *.tif | *.tiff) echo "${1%%.tif*}" ;;
Correction - you want shortest suffix stripping, not longest suffix; so
this would be "${1%.tif*}" in case $1 is 'a.tif.b.tiff'.
> *) echo "$1" ;;
> esac
At any rate, the case statement is essential to ensure that only a
suffix of .tif or .tiff will be stripped, and that a file 'a.tif.bak'
will still be passed through verbatim.
--
Eric Blake address@hidden +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature