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:8862 | -Ray, January 22, 2008
More Programming articles...

Tallahassee Abstract Art

Selected articles

Apple to Intel move no threat to Linux

Missing the point of the Mac Mini

Tutorial: Introduction to Linux files

Hacker Haiku

Shadow.sh: A simple directory shadowing script for Linux

Programming Language Tradeoffs: 3GL vs 4GL

 

Firefox sidebar

Site map

Site info

News feed

Features

Login
(to post)

Search

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