The attached file shows how to launch a terminal in the background, wait for the shells PID to show up, and retrieve its TTY.
You can then use it to display text and send ANSI escape sequences to control color and cursor position. The script includes
variables to set the size, position, and font for the terminal. It sets up a variable called TTY that you can echo text into.
You can send formated text (fixed width, left justify, right justify, etc.) to TTY using printf.
To use it you can
1. Source it as is into a script. In that case it will run automatically and set TTY.
2. Define it as a function to be called only if you need it.
3. Add your own code to the end of the file.
Defining it as a function can make for a handy debugging option. For instance, calling it NewTerminal and it will set up
a variable called TTY.
# Redirect unwanted output to $Null instead of /dev/null.
Null="/dev/null"
# Set DEBUG to 1 to enable debugging output.
DEBUG=0
if [ "$DEBUG" == 1 ]
then
# Launch a new terminal and find out which TTY its connected to.
NewTerminal
# Redirect Null to the TTY.
Null=$TTY
# Turn on script debugging and redirect it.
-x
exec 1>$TTY
exec 2>%1
fi
Examples of adding code to the end of the file:
Script to create a real barebones desktop clock
http://forum.tinycorelinux.net/index.php/topic,13794.msg150397.html#msg150397Script to display remaining battery charge
http://forum.tinycorelinux.net/index.php/topic,23880.msg150398.html#msg150398 [EDIT]: Corrected the contents inside the code tags. Corrected shebang in the attachment. Rich.