Extract filename and extension in Bash

后端 未结 30 1975
野趣味
野趣味 2020-11-21 05:29

I want to get the filename (without extension) and the extension separately.

The best solution I found so far is:

NAME=`echo \"$FILE\" | cut -d\'.\'          


        
30条回答
  •  独厮守ぢ
    2020-11-21 06:14

    Smallest and simplest solution (in single line) is:

    $ file=/blaabla/bla/blah/foo.txt
    echo $(basename ${file%.*}) # foo
    

提交回复
热议问题