使用Shell Scripting检查文件的扩展名

时间:2012-12-16 18:49:31

标签: shell csh

我需要将一个文件作为参数发送到我的C Shell脚本。现在我需要检查它是带有.xml扩展名的文件还是包含扩展名为.xml的文件列表的文件。

1 个答案:

答案 0 :(得分:3)

我没有办法测试这个,但我过去使用csh的经历告诉我像

 #!/bin/csh

 file="$1"

 switch ("$file")
     case *.xml:
         echo "file matches .xml"
      breaksw
     default:
         if ( grep '\.xml$' "$file" )  then
            echo "xml file extensions found in $file"
         endif
     breaksw
  endswitch

应该有用。

IHTH