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

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

1
如果$file包含文件名(例如foo.xml),那么$file:e会给出扩展名(在这种情况下为xml)。 - Keith Thompson
1个回答

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接