help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] The best way to trim trailing .tiff or .tif?


From: Peng Yu
Subject: [Help-bash] The best way to trim trailing .tiff or .tif?
Date: Thu, 4 Oct 2012 21:02:39 -0500

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


-- 
Regards,
Peng



reply via email to

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