在bash脚本中获取星期几 [英] Get Day Of Week in bash script

查看:64
本文介绍了在bash脚本中获取星期几的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在变量 DOW 中添加星期几.

I want to have the day of week in the variable DOW.

所以我使用以下bash脚本:

So I use the following bash-script:

DOM=$(date +%d)
DOW=($($DOM % 7) ) | sed 's/^0*//'

不幸的是,我得到以下错误: bash:09:命令未找到.在变量 $ DOW 中,预期结果为2(9%7 = 2).

Unfortunately there I get this error: bash: 09: command not found. The expected result is 2 ( 9 % 7 = 2) in the variable $DOW.

如何使它正常工作?它适用于1-8天,但是由于C十六进制,没有可用的数字超过8,并且出现以下消息: bash:09:值对于基数太大(错误标记为"09").

How can I get this working? It works for the days 1-8 but because of the C-hex, there is no number over 8 available and the following message appears: bash: 09: value too great for base (error token is "09").

推荐答案

使用%u .像这样:

DOW=$(date +%u)

手册页中:

%u星期几(1..7);1是星期一

%u day of week (1..7); 1 is Monday

这篇关于在bash脚本中获取星期几的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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