0

I'm trying to use the recipe found in a comment on

Extract filename and extension in Bash

Namely, for

file="example.tar.gz"

I'm trying to do

echo "${file#.*}"

and

echo "${file##.*}"

but both return

example.tar.gz

as opposed to what's written in that comment (tar.gz and gz respectively).

Fedora 16 GNU bash, version 4.2.20(1)-release (x86_64-redhat-linux-gnu)

Shall I file a bug?

Community
  • 1
  • 1
iksemyonov
  • 4,106
  • 1
  • 22
  • 42

2 Answers2

2

What you want is ${file#*.} and ${file##*.} - i.e. '*.', not '.*' The deletion is from the left, so you want it to stop at the full stop (whereas in your case it is looking for a . at the beginning of the string and failing). See this article on bash string operators for a very good and succinct explanation.

ShankarG
  • 1,105
  • 11
  • 26
0

Ohh sorry. Mixed up the position of the dot and the asterisk. Closing as the question is incorrect.

iksemyonov
  • 4,106
  • 1
  • 22
  • 42