59.9k views
5 votes
Write a shell script called SpellOutDate that prints the detail of the current date in separate lines. For example if the current date on the system is Thu Jan 30 10:57:20 CST 2020 Then when you run your script as: $ SpellOutDate Then the output should be: Time: 10:57:20 Today is: Thursday Day of the month: 30 Month: January Year: 2020

User Ciriarte
by
7.3k points

1 Answer

4 votes

Answer:

Hi there! We can use the "date" function and formats available to us along with the "echo"command to print the date in the format required in the question. Please see below for the details.

Step-by-step explanation:

SpellOutDate.sh

#!/bin/bash

echo "Time: $(date +'%T')"

echo "Today is: $(date +'%A')"

echo "Day of Month: $(date +'%u')"

echo "Month: $(date +'%B')"

echo "Year: $(date +'%G')"

running from the command line, the code will produce the results as:

./SpellOutDate.sh

Time: 11:12:53

Today is: Monday

Day of Month: 1

Month: March

Year: 2020

User William R
by
7.9k points