Shell Scripting - part 3

Fun with Shell scripting
-------------------------
----


tput cup command
-----------------
This command is used to set properties of terminal

tput cup 0 0
This command will set courser position to top left corner of terminal

e.g:-
[root@localhost]#vi file6.sh
tput cup 0 0
echo "Ansil"


Save and execute script
The output "Ansil" will be displayed on top left corner of the terminal

e.g:-
Lets make this example more interesting

#!/bin/bash
clear
tput cup 12 35
echo "Ansil"
read

Save the file and execute the script
The out put will display "Ansil" on almost center of the screen,
Surprisingly you will not get your terminal back until you press enter OR you have to kill/terminate the script(we will discuss this later)

The read command is used to read values from terminal(by default standard input)

here the read command read values till an occurrence of ENTER key ,but the value will not be stored

e.g:-
Make this example some more interesting

#!/bin/bash
clear
tput cup 12 35
echo -e "\033[31mAnsil\033[0m"
read

The echo line having some extra characters ..!!

More on echo command
---------------------------
echo -e --->what is -e
:- enable interpretation of backslash escapes
echo -e "\033[31m ------>what is \033[31m
:-Start printing charecter from here in red
:-\033[ is a backslash escape character
:- in 31 3-forground 1-for red
echo -e"\033[31mAnsil" ----->It will print Ansil in red color ,Then why

echo -e "\033[31mAnsil\033[0m"
:-The \033[0m will make the terminal to normal state
:- i,e from \033[0m the characters will be printed normally
:- If you did't typed this on your script ,after execution also the character printed will be in red

Colors and attributes using echo
---------------------------------
Foreground
-----------
\033[30m - BLACK
\033[31m - RED
\033[32m - GREEN
\033[33m - YELLOW
\033[34m - BLUE
\033[35m - MAGENTA
\033[36m - CYAN
\033[37m - WHITE

background
-----------
\033[41m - BLACK
\033[41m - RED
\033[42m - GREEN
\033[43m - YELLOW
\033[44m - BLUE
\033[45m - MAGENTA
\033[46m - CYAN
\033[47m - WHITE
More
------------
\033[4m - UNDERLINE
\033[24m - STOP UNDERLINE
\033[5m - BLINK
\033[7m - INVERT FORGROUND AND BACKGROUNG
\033[1m - BOLD

e.g:-
print Ansil in bold with color green and background red in bottom right corner of terminal

#!/bin/bash
clear
tput cup 23 00
echo -e "\033[41m\033[32m\033[1mAnsil\033[0m"

we will split the echo line
echo -e ---->You know this
\033[41m --->Make background red
\033[32m --->Make foreground green
\033[1m ---->Make foreground bold
Ansil -------->The word to be printed
\033[0m ---->Make default printing colors

Comments

Popular posts from this blog

How to Configure YUM in RHEL6

How to Configure Squid with Mysql DB authentication

HMC vtmenu exit