#!/bin/bash
echo -e "Hello World!!!!\a\n"
:<<'EOF'
#!/bin/bash
echo -e "\n*****数据计算******* \a"
a=10
b=20
echo $(($a+$b))
echo $((100+20-20*2))
#!/bin/bash
filename=/home/test/test.sh
echo -e "\n*****判断文件是否存在/home/test/test.sh is exist or not exist******* \a"
test -f $filename && echo 'exist' || 'not exist'
#!/bin/bash
echo -e "\n*****[]判断******* \a"
[ '12' == '10' ]&&echo 'yes' || echo 'no'
a=10
b=20
[ "$a" != "$b" ]&&echo 'yes' || echo 'no'
#!/bin/bash
echo -e "\n****if和[之间要有空格 双分支******* \a"
if [ '12' != '10' ]; then
echo '12 is not equal 10'
else
echo ' 12 is equal 10 '
fi
#!/bin/bash
#echo -e "\n****多分支******* \a"
#echo '输入一个值:'
#read number
#if [ $number == 1 ];then
# echo '你输入的数是:1'
#elif [ $number == 2 ];then
# echo '你输入的数是:2'
#else
# echo '错误'
#fi
#!/bin/bash
echo '输入要查看的硬件信息【cpu,mem,hard】:'
read hd
if [ $hd == cpu ];then
cat /proc/cpuinfo
elif [ $hd == mem ];then
cat /proc/meminfo
elif [ $hd == hard ];then
df -h
else
echo '错误'
fi
#!/bin/bash
echo '输入一个值:'
read number
case $number in
1)
echo '1';;
2)
echo '2';;
*)
echo '错误';;
esac
#!/bin/bash
echo '输入一个值:'
read i
while [ $i -eq 5 ];do
echo $i;
((i--));
done;
#!/bin/bash
echo -e "\n****for循环******* \a"
for((i=1;i<=10;i++));do
echo $i
done;
#!/bin/bash
echo -e "\n****函数(方法)******* \a"
function print(){
echo '$1'
}
case $1 in
"one")
print 1;;
"two")
print 2;;
*)
print '错误';;
esac
#! /bin/bash
function sum()
{
returnValue=$(( $1 + $2 ))
return $returnValue
}
sum 22 4
echo $?
EOF
#ocal一般用于局部变量声明,多在在函数内部使用。
#(1)shell脚本中定义的变量是global的,其作用域从被定义的地方开始,到shell结束或被显示删除的地方为止。
#(2)shell函数定义的变量默认是global的,其作用域从“函数被调用时执行变量定义的地方”开始,到shell结束或被显示删除处为止。函数定义的变量可以被显示定义成local的,其作用域局限于函数内。但请注意,函数的参数是local的。
#(3)如果同名,Shell函数定义的local变量会屏蔽脚本定义的global变量。
#!/bin/bash
function ai_log()
{
[ $# -ne 2 ] && return 0
case $1 in
-E|-e)
echo -e "[ERROR]$(date +%Y-%m-%d\ %H:%M:%S)\t[${FUNCNAME[1]}]:\t\033[1;31m${2}\033[0m" >> "${log_file}"
echo -e "[ERROR]$(date +%Y-%m-%d\ %H:%M:%S)\t[${FUNCNAME[1]}]:\t\033[1;31m${2}\033[0m"
;;
-I|-i)
echo -e "[INFO]$(date +%Y-%m-%d\ %H:%M:%S)\t[${FUNCNAME[1]}]:\t${2}" >> "${log_file}"
echo -e "[INFO]$(date +%Y-%m-%d\ %H:%M:%S)\t[${FUNCNAME[1]}]:\t${2}"
;;
-D|-d)
echo -e "[DEBUG]$(date +%Y-%m-%d\ %H:%M:%S)\t[${FUNCNAME[1]}]:\t\033[1;32m${2}\033[0m" >> "${log_file}"
echo -e "[DEBUG]$(date +%Y-%m-%d\ %H:%M:%S)\t[${FUNCNAME[1]}]:\t\033[1;32m${2}\033[0m"
;;
esac
}
chown uc_ims:oinstall /home/test/usgserverDB -R || return 1
su - uc_ims -c "dbopt -b exec_sql -l \"drop schema aaaa cascAde;\" -u public -U uc_ims -D imsuportal -I UTF8"
[ $? -ne 0 ] && return 1
if [ $? -ne 0 ];then
ai_log -I "drop PT schema ${SCHEMA_DST} result is failed, but we can ignore."
else
ai_log -I "drop PT schema ${SCHEMA_DST} result is success."
fi