You get a bonus - 1 coin for daily activity. Now you have 1 coin

bash/sh: How to Determine the Number of Days in the Current Month in a Script

Practice



Today our task is: determine the number of days in the current month (31, 30, 29, or 28) — with a simple one-line expression in a bash or sh script.

Solution:
date -d "`date +'%m/01'`+1month -1day" +%d

Or inside a script:
#!/bin/sh

a=`date -d "\`date +'%m/01'\`+1month -1day" +%d`
echo $a

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "LINUX operating system"

Terms: LINUX operating system