1 提示用户输入密码信息
#!/bin/bash
# AUTHOR:L** G*** **********************
# CREATED:14/03/2019 16:19
> read -sp 'ents password:' pass
if test "$pass" == "wangluo" ;then
echo -e "\npassword verified"
exit 0
else
echo -e "\nAccess denied"
exit 1
fi
[wangluo@localhost 桌面]$ sh Checkpasswd.sh # (不是正确密码)
ents password:
Access denied
[wangluo@localhost 桌面]$ sh Checkpasswd.sh # (正确密码)
ents password:
password verified
2 嵌套的if/else语句
#!bin/bash
# Qiantaoyuju
# Li Gang
# 19.03.2019
#===============================
declare -i count
#===============================
read -p "Enter an count: " count
if [ $count -eq 100 ];then
echo "count is 100"
else
if [ $count -lt 100 ];then
echo "count is greater than 100"
else
echo "count is less than 100"
fi
#===============================
fi
#!/bin/bash
# this is a jiaoben
#=====================
if [ $# -eq 0 ];then
echo "$0 :you must give one integers"
exit 1
fi
if
[ $1 -lt 0 ];then
echo "the number is negative"
elif
[ $1 -gt 0 ];then
echo "the number is positive"
elif
[ $1 -eq 0 ];then
echo "the number is 0"
else
echo "opps! $1 is not number, give numder"
fi
查成绩
if [ $# -ge 0 ];then
echo "shuruzi"
exit 1
fi
num=$1
if
[ $num -ge 90 ]&&[ $num -le 100 ];then
echo "youxiu"
elif
[ $num -ge 70 ]&&[ $num -le 89 ];then
echo "lianghao"
elif
[ $num -ge 60 ]&&[ $num -le 69 ];then
echo "jige"
elif
[ $num -ge 0 ]&&[ $num -le 59 ];then
echo "bujige"
else
echo "zhebushishuzi"
fi
for 循环 的九九乘法表
正序
for (( i = 1; i < 10; i++ ))
do
for (( j = 1; j = i; j++ ))
do
echo -ne "${j}*${i} $(( j*i ))\t"
done
echo ""
done
倒序
for (( i = 9; i > 1; i--))
do
for (( j = 9; j = i; j-- ))
do
echo -ne "${j}*${i} $(( i*j ))\t"
done
echo ""
done
while 循环
#!/bin/bash
file=$1
if [ $# -lt 1 ];then
echo "Usage: $0 FILEPATH."
exit
fi
while read -r line
do
echo $line
done < "$file"
一个死循环
#!/bin/bash
while :
do
echo "do something..."
echo "hit [ sssss ]"
done
用死循环查看时间和系统 而且清屏
#!/bin/bash
##
#
##======================
read -p "132456" s
while :
do
clear
case $s in
1)
date
read -p "123456" s
;;
2)
uname -a
read -p "123456" s
;;
esac
done
~
select 循环
#!/bin/bash
PS3="Run command:"
select choice in date w hostname "uname -a" Exit
do
case $choice in
date)
echo "now time is :"
$choice
;;
w)
echo "who is logged on :"
$choice
;;
hostname)
echo "Hostname:"
$choice
;;
"uname -a")
echo "system in:"
$choice
;;
Exit)
echo "baibai"
exit
;;
esac
done
求和
#!/bin/bash
#
#
#
#
#
#
SUM=0
while :
do
read -p "123 :" a
[ $x -eq 0 ] && break
SUM=$[ SUM+x ]
done
echo "heshi $SUM"
20以内6的陪数的平方
#!/bin/bash
#
#
#
#
#
for i in {1..20}
do
[ $[ i%6 ] -ne 0 ]&& continue
echo $[ i*i ]
done
十全十美花数
#!/bin/bash
for ((a = 1; a < 10;a++ ))
do
for (( b = 0; b < 10; b++ ))
do
for (( c = 0; c < 10; c++ ))
do
for (( d = 0; d < 10; d++ ))
do
for (( f = 0; f < 10; f++ ))
do
for (( g = 0; g < 10; g++ ))
do
for (( h = 0; h < 10; h++ ))
do
for (( j = 0; j < 10; j++))
do
for (( k = 0; k < 10; k++ ))
do
for (( l = 0; l < 10; l++ ))
do
i=$(( a * 1000000000 + b * 100000000 + c * 10000000 + d * 1000000 + f * 100000 + g * 10000 + h * 1000 + j * 100 + k * 10 + l ))
x=$(( a**10 + b**10 + c**10 + d**10 + f**10 + g **10 + h **10 + j **10 + k **10 + l **10 ))
if [ $i -eq $x ];then
echo $i
fi
done
done
done
done
done
done
done
done
done
done
local 位置变量
#!/bin/bash
d=/tmp/diskusage.log
create_logFile () {
local d=$4
echo "d is $d"
}
echo "d is $d"
create_logFile /etc /etc/disk.lo
echo "d is $d"
实现123*4…*5
for 循环
#!/bin/bash
#sun=1
#o=$1
#for (( i = 1; i <= o; i++ ))
#do
#sun=$[ sun*i ]
#done
#echo "$sun"
while循环
#sun=1
#o=1
#while (( o <= $1 ))
#do
#sun=$[sun*o]
#let o++
#done
#echo "$sun"
创建密码
#!/bin/bash
x=qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890
pass=''
for i in {1..8}
do
num=$[RANDOM%62]
tmp=${x:num:1}
pass=${pass}$tmp
done
echo "$pass"