linux bash sh shell,Linux bash shell.sh编程实例

1.输出

#!/bin/bash

echo "Please type your number:"

read a

for ((i=1;i<=a;i++))

do

for ((p=1;p<=i;p++))

do

echo -n " $p "

done

echo

done

echo

2.九九乘法表

#!/bin/bash

for ((i=1;i<10;i++))

do

for ((p=1;p<=i;p++))

do

echo -ne " $p x $i= "`expr $i \* $p`

done

echo

done

echo

3.计算器

#!/bin/bash

s=0

while true

echo "..............+"

echo "..............-"

echo "..............x"

echo "............../"

echo "..............q"

echo "Please type your word:(e.g.1 + 2)"

read a b c

do

case $b in

+)

let s=a+c

echo " $a + $c =" $s;;

-)

let s=a-c

echo " $a - $c =" $s;;

\x)

let s=a*c

echo " $a x $c =" $s;;

\/)

let s=a/c

echo " $a / $c =" $s;;

esac

case $a in

q) break ;;

esac

done

4.菱形

#!/bin/bash

echo "Please type a number:"

read num

for ((i=1;i<=num;i++))

do

for ((j=0;j

do

echo -n " "

done

for ((j=0;j<2*i-1;j++))

do

echo -n "*"

done

echo ""

done

for ((i=1;i<=num;i++))

do

for ((j=0;j

do

echo -n " "

done

for ((j=0;j<2*(num-i)-1;j++))

do

echo -n "*"

done

echo ""

done

5. 输出当前目录下所有文件,并输出文件总数和目录总数

#!/bin/bash

ls -al

filenum=0

dirnum=0

for q in `ls -a`

do

if [ -d $q ]

then

dirnum=`expr $dirnum + 1`

fi

filenum=`expr $filenum + 1`

done

echo "The number of dirctary is $dirnum"

echo "The number of file is $filenum"

6.菜单

#!/bin/bash

while true

echo "List Directory..........l "

echo "Change Directory........c "

echo "Edit File...............e "

echo "Remove File.............r "

echo "Exit Menu...............q "

read ch

do

case $ch in

l) ls;;

c) echo Enter target directory

read direc

cd "$direc" ;;

e) echo Enter file name

read file

vi $file ;;

r) echo Enter file name

read file

rm $file ;;

q|Q) echo Goodbye

break;;

*) echo illegal Option

esac

done0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值