0

如何验证给定的参数格式,根据参数格式将执行不同的脚本。例如:我有 script.sh 并以两种不同的格式传递 to 参数(一种是日期参数,另一种是 ids),我只想检查日期格式,不完全是日期,我用下面的脚本检查但没有用在 Ubuntu 和 rhel 中。

...
    #!/usr/bin/bash
    Para1=$1
    Para2=$2
     if [[ $Para1 =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ] && [ $Para2 =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ] ]     
     then 
     Echo "execute blah blah.."
   else
    if [[ $Para1 =~ ^[0-9a-zA-Z]{9}$ ] && [ $Para2 =~ ^[0-9a-zA-Z]{9}$ ] ]          
       then
       echo "execute the script"
        else `enter code here`
          echo "please pass the right ids.
    fi
    fi  
...

请让我知道缺少什么。

4

0 回答 0