我想要的是用户使用zenity从任何地方选择一个文件,脚本将检测文件扩展名,例如(.tar.gz)或(.zip),并相应地对它们执行操作。这是一个例子。
#! /bin/bash
FILE=$(zenity --file-selection --title="Select a file to check")
echo "File: $FILE"
if [ "$FILE" = "*.zip" ]
then
echo "File that is a .zip found"
FILENAMENOEXT="${FILE%.*}"
echo "Filename with extention $FILENAMENOEXT"
#Perform xx action to $FILE if it is a zip
elif [ "$FILE" = "*.tar.gz" ]
then
echo "File is a .tar.gz found"
FILENAMENOEXT="${FILE%.tar.*}"
echo "Filename with extention $FILENAMENOEXT"
#Perform xx action to $FILE if it is a t.tar.gz
else
echo "File is neither .zip nor .tar.gz"
fi
echo "test $FILENAMENOEXT"