A bash script for tool version test

由于blog中已有关于shell的一些描述,因此对命令不再赘述。以下是学习中练习过的一个简单脚本,主要是对系统中的工具版本以及编译环境等进行测试,目的是熟悉各种命令的具体运用。

script name : wls

run command :$  . wls (or source  wls)

$ help     : print executable commands   (all , android ,check_gcc,check_java ...)

#!/bin/sh

######################## introduction script ###########################
function help()
{
echo
cat <<EOF
Invoke " . wls.sh" from your shell to add the following functions to your environment:

- all check all the softwares version
- android check the android environment
- check_make check the GNU MAKE version
- check_gcc check the GNU GCC version
- check_java check the Java version
- check_awk check the awk version
- check_git check the git version

The Above function name could be executed in the terminal!

EOF
echo
}

######################## OS and KERNEL VERSION ###########################

echo "------The Command \"help\" will give you a hand------ "
echo
echo -n "---- Your current OS and kernel version ---- "
uname -a | cut -d" " -f 1,3,11,12
echo

######################## get the version number ############################

make_version=`make -v 2>&1 | head -n 1 |sed "s/[a-zA-Z\"[:space:]]*//g"`
gcc_version=`gcc -v 2>&1 |sed "/^$/d" | tail -n 1 |cut -d " " -f 3 | sed "s/[^[1-9\.]].*//g" `
java_version=`java -version 2>&1 | head -n 1 | sed "s/[a-zA-Z\"[:space:]]*//g" | sed "s/\([0-9\.]*\).*/\1/g" `
awk_version=`awk --version 2>&1 | head -n 1| sed "s/[^[0-9\.]]*//g "`
git_version=`git --version 2>&1 | cut -d " " -f3 |sed "s/[a-zA-Z\"[:space:]]*//g " `

################### designate the appropriate version number #####################
version_num_make=3.81
version_num_gcc=3.4.1
version_num_java=1.4
version_num_awk=3.1.4
version_num_git=1.5.6
######################### check the MAKE version #############################
function check_make()
{

if [ -z "$make_version" ] ; then
echo "====== NO ====== You do not install < Make > yet !!!"
else
C=0
for i in 1 2 3 4
do
A=`echo $make_version | cut -d '.' -f $i`
B=`echo $version_num_make | cut -d '.' -f $i`
if [ "$A" == '' ] ; then
A=0
fi
if [ "$B" == '' ] ; then
B=0
fi
if [ "$A" == "$B" ] ; then
continue
elif [ "$A" -lt "$B" ] ; then
echo -n "====== NO ====== Make version $make_version ,"
echo " The Make Version need to update to $version_num_make . "
C=`expr $C + 1 `
break
else
echo "====== OK ====== `make -v 2>&1 | head -n 1`"
C=`expr $C + 1`
break
fi
done

if [ $C -eq 0 ] ; then
echo "====== OK ====== `make -v 2>&1 | head -n 1`"
fi
fi
echo
}

########################## check the GCC version ############################
function check_gcc()
{

if [ -z "$gcc_version" ] ; then
echo "====== NO ====== You do not install < GCC > yet !!!"
else
C=0
for i in 1 2 3 4
do
A=`echo $gcc_version | cut -d '.' -f $i`
B=`echo $version_num_gcc | cut -d '.' -f $i`
if [ "$A" == '' ] ; then
A=0
fi
if [ "$B" == '' ] ; then
B=0
fi
if [ "$A" == "$B" ] ; then
continue
elif [ "$A" -lt "$B" ] ; then
echo -n "====== NO ====== Gcc version $gcc_version ,"
echo " The Gcc Version need to update to $version_num_gcc . "
C=`expr $C + 1 `
break
else
echo "====== OK ====== `gcc -v 2>&1 | tail -n 1 `"
C=`expr $C + 1 `
break
fi
done

if [ $C -eq 0 ] ; then
echo "====== OK ====== `gcc -v 2>&1 | tail -n 1`"
fi
fi
echo
}

########################## check the Java version ############################
function check_java()
{
if [ -z "$java_version" ] ; then
echo "====== NO ====== You do not install < Java > yet !!!"
else
C=0
for i in 1 2 3 4
do
A=`echo $java_version | cut -d '.' -f $i`
B=`echo $version_num_java | cut -d '.' -f $i`
if [ "$A" == '' ] ; then
A=0
fi
if [ "$B" == '' ] ; then
B=0
fi
if [ "$A" == "$B" ] ; then
continue
elif [ "$A" -lt "$B" ] ; then
echo -n "====== NO ====== Java version $java_version ,"
echo " The Java Version need to update to $version_num_java . "
C=`expr $C + 1 `
break
else
echo "====== OK ====== `java -version 2>&1 | head -n 1 `"
C=`expr $C + 1 `
break
fi
done

if [ $C -eq 0 ] ; then
echo "====== OK ====== `java -version 2>&1 | head -n 1`"
fi
fi
echo

}

########################## check the Git version ############################
function check_git()
{

if [ -z "$git_version" ] ; then
echo "====== NO ====== You do not install < GIT > yet !!!"
else
C=0
for i in 1 2 3 4
do
A=`echo $git_version | cut -d '.' -f $i`
B=`echo $version_num_git | cut -d '.' -f $i`
if [ "$A" == '' ] ; then
A=0
fi
if [ "$B" == '' ] ; then
B=0
fi
if [ "$A" == "$B" ] ; then
continue
elif [ "$A" -lt "$B" ] ; then
echo -n "====== NO ====== Git version $git_version ,"
echo " The Java Version need to update to $version_num_git . "
C=`expr $C + 1 `
break
else
echo "====== OK ====== `git --version 2>&1 | head -n 1 `"
C=`expr $C + 1 `
break
fi
done

if [ $C -eq 0 ] ; then
echo "====== OK ====== `git --version 2>&1 | head -n 1`"
fi
fi
echo

}

########################## check the Awk version ############################
function check_awk()
{
if [ -z "$awk_version" ] ; then
echo "====== NO ====== You do not install < Awk > yet !!!"
else
C=0
for i in 1 2 3 4
do
A=`echo $awk_version | cut -d '.' -f $i`
B=`echo $version_num_awk | cut -d '.' -f $i`

if [ "$B" == '' ] ; then
B=0
fi
if [ "$A" == "$B" ] ; then
continue
elif [ "$A" -lt "$B" ] ; then
echo -n "====== NO ====== Awk version $awk_version ,"
echo " The Awk Version need to update to $version_num_awk . "
C=` expr $C + 1`
break
else
echo "====== OK ====== `awk --version 2>&1 | head -n 1`"
C=` expr $C + 1`
break
fi
done
if [ "$C" -eq 0 ] ; then
echo "====== OK ====== `awk --version 2>&1 | head -n 1`"
fi
fi
echo

}


########################## check android environment ############################
function android()
{
echo
echo "*android required environment checking*"
echo
check_gcc
check_java
check_make
check_git
echo
}

######################### check all the softwares version #############################
function all()
{
echo
check_make
check_java
check_gcc
check_awk
check_git
echo

}

你可能感兴趣的:(android,tool,bash)