How to check the extension of a filename in a bash script?

后端 未结 9 910
不思量自难忘°
不思量自难忘° 2020-12-04 05:33

I am writing a nightly build script in bash.
Everything is fine and dandy except for one little snag:


#!/bin/bash

for file in \"$PATH_TO_SOMEWHERE\"; d         


        
9条回答
  •  庸人自扰
    2020-12-04 05:55

    You just can't be sure on a Unix system, that a .txt file truly is a text file. Your best bet is to use "file". Maybe try using:

    file -ib "$file"
    

    Then you can use a list of MIME types to match against or parse the first part of the MIME where you get stuff like "text", "application", etc.

提交回复
热议问题