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:
Set variable _now for the current time
_now=$(date +"%T") echo "Current time : ${_now}"
The screen output terminal:
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
Conclusion
Thought the article, you can use Bash script read time. I hope will this your helpful. More details refer to Bash script.