前言
本文脚本,在UOS通过上测试。
脚本代码
#!/bin/bash echo 请将q7文件拖入: read file file=`echo "$file"|sed s/\'//g` #去除文件名前后的单引号 ' 否则以后的判断就不对了 isq7=`echo "$file"|awk -F. '{print $NF}'` if [ $isq7 != "q7" ];then echo 后缀名不是.q7.脚本将退出2! read -n 1 exit fi if [ -e "$file" ];then #文件存在为真 time=`cat "$file"|grep --binary-files=text 'date'|awk -F, '{print $4}'` echo -e $time "\n" year=`echo $time|awk '{print $6}'|cut -c 1-4` month=`echo $time|awk '{print $2}'` if [ $month = "Jan" ];then #sh中,文本比较一致 = 而不是 == month="1" elif [ $month = "Feb" ];then month="2" elif [ $month = "Mar" ];then month="3" elif [ $month = "Apr" ];then month="4" elif [ $month = "May" ];then month="5" elif [ $month = "Jun" ];then month="6" elif [ $month = "Jul" ];then month="7" elif [ $month = "Aug" ];then month="8" elif [ $month = "Sep" ];then month="9" elif [ $month = "Oct" ];then month="10" elif [ $month = "Nov" ];then month="11" elif [ $month = "Dec" ];then month="12" fi echo 签名时间:$year年 $month月 echo 签名有效期一般为一年,签名后一个月可以设置时间 else echo "q文件不存在,请检查输入!" fi read -n 1 #skyyx2002 #2022.06.28
将上面的脚本保存(最好在Linux上操作,Windows在执行换行符等问题时可能会出错),如:
使用方法
先给脚本执行权:
chmod 777 获取q7.文件签名日期.sh #注意修改文件路径和文件名称
然后双击脚本,弹出以下对话框:
弹出:
将q将文件拖到终端窗口后放开,使终端窗口能够获得文件的完整路径和名称:
此时点击终端窗口,按下回车,即可获得签名时间:
一些问题
1、如果使用sh命令调用脚本,然后最后一句read -n 一是执行失败!因此,不建议使用sh调用,可用bash。假如真的喜欢用sh,然后添加参数:sh -c
2.脚本放在U盘上时,要注意U盘的分区格式!Fat32是不支持Linux所以直接双击脚本,默认会用文本编辑器打开,脚本不会执行!U盘分区可以格式化为exFat或者ntfs,或者使用bash调用脚本。