Librenix  
(Show all Scripting articles . . .
)  
Headlines | Linux | Apps | Coding | BSD | Admin | News
Information for Linux System Administration 

Scripting: Put a clock in your bash terminal

Up
vote
Down

In the original version, the cursor positioning didn't work on my Mac OS X system. If that happens to you, try this simplified variant:
  #!/bin/bash
while true
do
tput sc
tput cup 0 60
echo -en `date +"%H:%M:%S %F"`
tput rc
sleep 1
done
Also, note that you'll need to run either script in the background to use your terminal.
The script saves the current cursor position with an ANSI escape sequence instruction. Then, using the tput command, the cursor is sent to row 0 (the top of the screen) and the last column minus 19 characters (19 is the length of HH:MM:SS YYYY-MM-DD). The formatted date command is displayed in green inverted color. The cursor is then sent back to its original position with another ANSI sequence that restores the original saved position.
 read more | mail this link | score:8971 | -Ray, January 22, 2008
More Programming articles...

Abstract Art Prints by Ray Yeargin

coding headlines

OpenShift Online: a non-developer guide

Tutorial: Create an NFS-like Storage Server with GlusterFS on Ubuntu 12.10

Introduction to Perl one-liners

Tutorial: Install SVN, Configure multi-protocol access (Ubuntu 11.10)

bash scripting: Looping through a list

Debugging Shell Scripts

 

Firefox sidebar

Site map

Site info

News feed

Features

Login
(to post)

Search

 
Articles are owned by their authors.   © 2000-2012 Ray Yeargin