help-bash
[Top][All Lists]
Advanced

[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: Davide Brini
Subject: Re: [Help-bash] The best way to trim trailing .tiff or .tif?
Date: Fri, 5 Oct 2012 12:01:49 +0200

On Thu, 4 Oct 2012 21:02:39 -0500, Peng Yu <address@hidden> wrote:

> Hi,
> 
> There can be many ways to trim .tiff or .tif from a filename. I'm
> using the following code (fairly verbose). I'm sure there should be a
> more concise (meaning less typing) way of doing it. Could anybody let
> me know what is the most concise way? Thanks!
> 
> /tmp$ ./test.sh
> tmp
> tmp
> tmp_xxx
> /tmp$ cat ./test.sh
> #!/usr/bin/env bash
> 
> function cmd {
> local f="$1"
> if [[ "$f" =~ \.*.tiff ]]
> then
>   echo "${f%.tiff}"
> elif [[ "$f" =~ \.*.tif ]]
> then
>   echo "${f%.tif}"
> else
>   echo "$f"
> fi
> }
> 
> cmd tmp.tif
> cmd tmp.tiff
> cmd tmp_xxx

With extended globbing one could do

printf '%s\n' "${f%@(.tiff|.tif)}"

-- 
D.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]