Get extension of files in Bash

Viewed 12775

I am writing a script which will sort files by extensions. I know a method to do this by file's names. The problem is, that same files haven't got extension in their names. For example if I have file: file.txt there is no problem to get an extension by simple extension="${filename##*.}". But if file name is just filename this method doesn't work. Is there any other option to get extension of file and put it to variable in Bash script?

5 Answers
Related