如何通过Shell脚本检查文件名格式? [英] How to check file name format through shell script?

查看:383
本文介绍了如何通过Shell脚本检查文件名格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我编写了一个shell脚本,该脚本接受输入文件作为cmd行参数并处理该文件.

Hello,

I had written a shell script that accepts input file as cmd line argument and process this file.

if [ $# -eq 1 ]; then
 if [ -f $1 ]; then
   . $1
   LOGFILE="$LOG_FILE/MIG_BIOS.log";
    get_input_file

 else
  ERROR_CODE=MSCRM0005_003
  error "$ERROR_CODE : Input file $1 is not available";
  exit 1
 fi

else
 echo "usage : $usage";
fi


我需要帮助来编写用于检查文件名格式的get_input_file函数.
我的输入文件名格式是MIG_CR_< TYPE> _< TIMESTAMP>.< EXT>


I want a help in writting a get_input_file function which checks for file name format.
My input file name format is MIG_CR_<TYPE>_<TIMESTAMP>.<EXT>

get_input_file()
{
FILE = ''$1''
# checking file exist or not
if [ ! -f $FILE ]; then
    echo "$FILE : does not exists";
    exit 1
elif [ ! -r $FILE ]; then
    echo "$FILE: can not read";
    exit 2
fi

// TO do
// check file name foramt is correct or not
}


谁能告诉我如何检查文件名的格式?
请帮帮我.


Can anyone tell me how can I check the format of file name?
Please help me out. Thanks in advance.

推荐答案

#-eq 1];然后 如果[-f
# -eq 1 ]; then if [ -f


1];然后 .
1 ]; then .


1 LOGFILE ="
1 LOGFILE="


这篇关于如何通过Shell脚本检查文件名格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆