Extract filename and extension in Bash

后端 未结 30 2732
野趣味
野趣味 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:12

    Building from Petesh answer, if only the filename is needed, both path and extension can be stripped in a single line,

    filename=$(basename ${fullname%.*})
    

提交回复
热议问题