使用Cshell脚本检查文件扩展名

使用Cshell脚本检查文件扩展名,shell,csh,Shell,Csh,我需要向我的C Shell脚本发送一个文件作为参数。现在,我需要检查它是扩展名为.xml的文件还是包含扩展名为.xml的文件列表的文件。我没有办法测试这一点,但我过去使用csh的经验告诉我 #!/bin/csh file="$1" switch ("$file") case *.xml: echo "file matches .xml" breaksw default: if ( grep '\.xml$' "$fil

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

我没有办法测试这一点,但我过去使用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

如果
$file
包含文件名(例如
foo.xml
),则
$file:e
提供扩展名(
xml
)。