如果今天的日期已经过了 X 日期,则在 Ubuntu Bash 脚本中执行内容

Eri*_*kli 2 command-line bash scripts

我正在创建一个 bash 脚本许可证系统。我想制作一个名为 End-Date 的系统,该系统将检查今天的日期是否已经过了特定日期,然后我想运行命令。通过示例您会更好地理解它。

例如

#Lets say today is 30.08.2022
scriptdate=30.08.2022
enddate=29.08.2022
#If the $scriptdate has passed the $enddate then run exit command
Run Code Online (Sandbox Code Playgroud)

gle*_*man 6

使用YYYY-mm-dd日期格式,然后就是简单的字符串比较

today=$(date +%Y-%m-%d)
enddate="2022-08-29"

if [[ "$today" > "$enddate" ]]; then
    exit
fi
Run Code Online (Sandbox Code Playgroud)