Bash script read time

You can use the date command to display or set the current date and time. In this tutorial, I will write small program use Bash script read time. Bash script the essential for DevOps Roles.

The syntax of date command

date +"%FORMAT"

Show current time

[huupv@huupv devopsroles]$ date +"%T"

The screen output terminal:

Bash script read time

Set variable _now for the current time

_now=$(date +"%T")
echo "Current time : ${_now}"

The screen output terminal:

Bash script read time 2

Create bash script bash_read_time.sh file

#!/bin/bash
# Display text at given row and column
function show(){
  local x=$1
  local y=$2
  local txt="$3"
  tput cup $x $y
  echo "$txt"
}
while true
do
  clear
  # Get the system time 12 hour clock time
  now="$(date +"%r")"
  # Show main
  show 11 11 "MAIN MENU for $HOSTNAME - $now"
  show 11 11 "1. System info "
  show 12 11 "2. OS version "
  show 13 11 "3. Exit "
  tput cup 16 11; read -t 2 -p "Choice [1-3] ? " _select
  # do something
  case ${_select} in
    1) read -t 2 -p "Showing system info, wait..." ;;
    2) read -t 2 -p "Showing apache info, wait..." ;;
    3) echo "Bye."; exit 0;;
  esac
done

Run bash script read time

[huupv@huupv devopsroles]$ chmod +x bash_read_time.sh
[huupv@huupv devopsroles]$ ./bash_read_time.sh

Bash script read time 3

Conclusion

Thought the article, you can use Bash script read time. I hope will this your helpful. More details refer to Bash script.

About HuuPV

My name is Huu. I love technology, especially Devops Skill such as Docker, vagrant, git, and so forth. I like open-sources, so I created DevopsRoles.com to share the knowledge I have acquired. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.