Shell脚步编程

Test

程序1

#!/bin/bash

A="how"
B="h"
test $A = $B
echo $?

程序2

#!/bin/bash

A=10
B=99
test $B -gt $A
echo $?

if语句

程序1

Shell脚步编程

#!/bin/bash

if [ $# -d 1 ]
then
	echo "usage:$0 filename"
	exit
fi

if ! [ -e $1]
then
	echo "$1 not exist"
fi

程序2

Shell脚步编程

#!/bin/bash
echo "程序人生"

if [ $# -d 1 ]
then
        echo "usage:$0 filename"
        exit
else
        echo "$0目录不存在"
fi

case.sh

#!/bin/bash

echo "please choose (yes|no)"
read R

case $R in
	yes)
		echo "yes"
		;;
	no)
		echo "no"
		;;
	*)
		echo "wrong"
		#;;
esac

echo -n "please input a score:"
read r
if [ $r -lt 0 -o $r -gt 100 ]
then
	echo "成绩不在100以内"
	exit
fi
a=`expr $r / 10`
case $a in
	9|10)
		echo "$r--A级"
		;;
	7|8)
		echo "$r--B级"
		;;
	6)
		echo "$r--C级"
		;;
	1|2|3|4|5|0)
		echo "$r--D级"
		;;
	*)
		echo "请输入正确分数"
		#;;
esac

read.sh

程序1

#!/bin/bash

echo "input a number:"
read num
echo $num

程序2

#!/bin/bash

echo "input a date:"
read Y M D
echo "The day is $Y-$M-$D"

prog1.sh

程序1

date
hostname
ls
ifconfig

程序2

echo "num:$#"
echo "all paras:$*"
echo "all paras:$@"
echo "\$0---$0"
echo "\$1---$1"
echo "\$2---$2"
echo "\$3---$3"
echo "\$4---$4"
echo "\$5---$5"
echo "\$6---$6"
echo "\$7---$7"
echo "\$8---$8"
echo "\$9---$9"
echo "\$10---${10}"
echo "\$11---${11}"

expr.sh

#!/bin/bash

a=`expr 3 + 4 \* 5`
echo $a

while.sh

#!/bin/bash

i=0
j=1
while [ $i -lt 10 ]
do
	while [ $j -lt $i ]
	do
		s=`expr $i \* $j`
		echo -n "$j*$i=$s "
		j=`expr $j + 1`
	done
		echo ""
		i=`expr $i + 1`
		j=1
done 

for.sh

九九乘法表-程序1

#!/bin/bash

echo "------------------------程序人生-------------------------"
for i in `seq 1 1 9`
do
	for j in `seq 1 1 $i`
	do
		s=`expr $j \* $i`
		echo -n "$j*$i=$s "
	done
	echo ""
done

九九乘法表-程序2

#!/bin/bash

for((i=1;i<=9;i++))
do
	for((j=1;j<=$i;j++))
	do
		s=`expr $j \* $i`
		echo -n "$j*$i=$s  "
	done
	echo ""
done

Shell脚步编程

上一篇:linux 配置nginx 开机自启动


下一篇:Linux常用操作命令总结