#!/bin/bash - shebang at the beginning of the script that will mean that script is bash compatible.
# - Comment, bash will not execute anything after # sign.
www.shellcheck.net - is very useful tool to verify your scripts.
echo - prints output and very useful tool to enter texts into the text files. Definitely, mostly used command in the script
true - means success and in Linux mostly defined as number '0'.
false - means fail and in Linux mostly defined as number '1'
I have little example script below to demonstrate some basics in real time.
function - function can define any function you would like to use in the script just like a variable. Format is: function [name of the function] { comment or command }
read - is a command that takes input from the user and transforms into a variable
[root@localhost ~]# cat check.sh
#!/bin/bash
# Author: Bek Azimov
# Created: 8/19/2014
function usage {
echo "ERROR: $abc is already in the system, where is rest of the script????????????? "
}
echo -n "Please, enter the service name: "
read abc
date >> check.log
rpm -qi $abc >> check.log
echo "<<<<<<<<<< line break >>>>>>>>>>" >> check.log
if [ $? -eq 1 ]
then yum install $abc -y
else echo "Service is already installed!" && usage
fi
exit 1
- - - - - - - - - - - - - - - -- - - - - - - - -- - - - - - -- - - - - - - - -- - - - - - - - - -- -- - -
# - Comment, bash will not execute anything after # sign.
www.shellcheck.net - is very useful tool to verify your scripts.
echo - prints output and very useful tool to enter texts into the text files. Definitely, mostly used command in the script
true - means success and in Linux mostly defined as number '0'.
false - means fail and in Linux mostly defined as number '1'
I have little example script below to demonstrate some basics in real time.
function - function can define any function you would like to use in the script just like a variable. Format is: function [name of the function] { comment or command }
read - is a command that takes input from the user and transforms into a variable
[root@localhost ~]# cat check.sh
#!/bin/bash
# Author: Bek Azimov
# Created: 8/19/2014
function usage {
echo "ERROR: $abc is already in the system, where is rest of the script????????????? "
}
echo -n "Please, enter the service name: "
read abc
date >> check.log
rpm -qi $abc >> check.log
echo "<<<<<<<<<< line break >>>>>>>>>>" >> check.log
if [ $? -eq 1 ]
then yum install $abc -y
else echo "Service is already installed!" && usage
fi
exit 1
- - - - - - - - - - - - - - - -- - - - - - - - -- - - - - - -- - - - - - - - -- - - - - - - - - -- -- - -
No comments:
Post a Comment