-1

I tried using $(date)in my bash shell script, however I want the date in YYYY-MM-DD +DAY + Mounth format.(if the month is 9 I do not want to display 09) How do I get this?

Piccolo
  • 11
  • 5

1 Answers1

0

Some versions of date can't display the month without the leading zero. You can use sed to remove it, though: the month is the only number surrounded by dashes:

date '+%Y-%m-%d %A %B' | sed 's/-0\([0-9]\)-/-\1-/'

Some versions support the padding modifiers. To turn padding off, use a dash:

date '+%Y-%-m-%d %A %B'
           ~

To change the language, just specify the locale:

$ LC_ALL=it_IT.UTF-8 date '+%Y-%m-%d %A %B' | sed 's/-0\([0-9]\)-/-\1-/'
2019-9-17 martedì settembre
choroba
  • 231,213
  • 25
  • 204
  • 289