我需要将文件作为参数发送到我的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
)。 - Keith Thompson