Shell Script to Display Time in Word Last Updated : 01 Nov, 2022 Comments Improve Suggest changes Like Article Like Report Linux/Unix has the inbuilt functionality to show the current time. Usually, Linux shows the current time in general format rather than word, and with this may some user can disagree. So, To show the current time in a better and pretty format here is given a bash script. It shows the current time in 12-hour format that will be in word style rather than general. If we direct run the time command in Linux or Unix then will get output like following Command: date +%r Output: 11:02:08 PM IST Our task is to Display Time in Word: Example: Current Time is : 02:03:25 AM IST Time in Word is : Two hour Three minutes Twenty-Five second AM Script Code Approach: To write the script for display the time in the world, we require some simple Linux inbuilt commands like "date", "echo" , Some basic shell scripting and through this, follow the below steps to write the script code.Get all time components like hour, minutes, and seconds in different variables.Make an array of strings that has the number from 0 to 19 in a word and use this word using the array index.Make another array of strings that will contain the value like 0,10,20,30,40,50,60 in word.Now, change the 24-hour format to a 12-hour format using an if-else statement.Create a function that takes an integer argument and returns that integer in word ( here number can be up to 2 digits because in time there is only number up to 2 digits).Now, convert all the components of time in the word and print the whole string of time using the "echo" command. Script Code: # ## bash script to display Time in word # print current time in original function format of Linux/Unix echo "Current Time is : " `date +%r` echo # getting hour, minutes and seconds value in separate as integer hour=`date +%-H` minutes=`date +%-M` seconds=`date +%-S` post='AM' # create array of strings two show time in word time=(Zero One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thirteen Fourteen Fifteen Sixteen Seventeen Eighteen Nineteen) time_ten=(Zero Ten Twenty Thirty Forty Fifty Sixty) # check hour is greater than "12" or not # if it than use 12-hour format to show the current time if [[ $hour -gt 11 ]] then let "hour -= 12" post="PM" fi # check if hour is 00 then print 12AM if [[ $hour -eq 0 ]] then let "hour = 12" fi # Function for get current hour,minutes and seconds in words function getNumber(){ # check condition when time is less than 20 and get value directly from array if [[ $1 -lt 20 ]] then timeInWord=${time[$1]} else # else block when time is greater than 20 ( minutes and seconds can be up to 59) f=`expr $1 / 10` s=`expr $1 % 10` # check condition when first part of the time is zero than we don't have to print that value if [[ $s -eq 0 ]] then timeInWord=${time_ten[$f]} else timeInWord="${time_ten[$f]}-${time[$s]}" fi fi } # make global variable for timeInWord timeInWord = "Geeks For Geeks" # get hour in word getNumber $hour hourInWord=$timeInWord # get minutes in word getNumber $minutes minutesInWord=$timeInWord # get seconds in word getNumber $seconds secondsInWord=$timeInWord # print time in usual and simple word format in one line echo "Time in Word is : $hourInWord hour $minutesInWord minutes $secondsInWord second $post" # END Output: Comment More infoAdvertise with us Next Article Shell Script to Display Time in Word A aditya32123 Follow Improve Article Tags : Linux-Unix Shell Script Similar Reads How to Print Specific date-time in Golang? Golang supports time formatting and parsing via pattern-based layouts. In Go, the current time can be determined by using time.Now(), provided by the time package. Package time provides functionality for measuring and displaying the time. To print Current date-time you need to import the "time" pack 2 min read Shell script to display Good Morning, Good Afternoon Good Evening according to system time In this article, we will see how to print Good Morning, Good Afternoon, Good Evening, and Good Night, according to system time using shell programming Example : # Program to print Good Morning, # Good Afternoon, Good Evening $ and Good Night, according to $ system time. #!/bin/bash hour=`date +%H` i 2 min read Create timestamp variable in bash script Handling timestamps is a common need in Bash scripting for a number of tasks, including file naming, data processing, and logging. Tracking events or organizing data can be made easier with the help of timestamps, which serve as a precise point-in-time representation. Creating timestamps in Bash scr 4 min read How to Display and Set Date and Time in Linux | date Command Unlock the full potential of the date command in Linuxâa versatile tool that does more than just show the current date and time. With this command, you can set your systemâs clock, synchronize time across networks, and even calculate past or future dates for tasks like scheduling or logging. In this 8 min read How to Get Current Time in JavaScript ? This article will show you how to get the current time in JavaScript. Whether you are creating a digital clock, scheduling events, or simply logging timestamps, knowing how to retrieve the current time is essential. Here, we will cover different methods to get the current time in JavaScript.Table of 2 min read How to Create Time-Table Schedule using HTML? A time table or schedule is essential for organizing tasks, events, or classes. Weâll create a basic time-table layout using HTML. A Table is an arrangement of rows and columns. Anyone can create a table by knowing the basics of HTML(HyperText Markup Language). In HTML we can use the <table> t 3 min read How to Add Time in Google Sheets - Complete Guide Time management is crucial, both in daily life and in spreadsheet mastery. In the dynamic world of spreadsheet management, Google Sheets stands out as a powerful tool for data manipulation and analysis. While basic arithmetic operations are easy to perform, dealing with time can be a bit tricky. In 12 min read Convert timestamp to readable date/time in PHP Problem: Convert timestamp to readable date/time in PHP Solution: This can be achieved with the help of date() function, which is an inbuilt function in PHP can be used to format the timestamp given by time() function. This function returns a string formatted according to the given format string usi 1 min read HTML | DOM Input Time Object The Input Time object in HTML DOM represents an <input> element with type = "time" attribute. The time attribute can be accessed by using getElementById() method. Syntax: document.getElementById("id"); where id is assigned to the <input> tag. Property Values: list: It returns the referen 3 min read Perl | Date and Time Perl is one of the most feature-rich programming languages. Perl is portable and cross-platform. Perl can run on over 100 platforms with highly integrated text processing ability. Perl contains the features of different languages like C, sed, awk, and sh etc. which makes the Perl more useful and pro 3 min read Like