设为首页 加入收藏

TOP

Linux bash shell.sh编程实例
2014-11-24 08:14:56 来源: 作者: 【 】 浏览:0
Tags: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


done


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android 开发之布局 下一篇使用intellij开发Android应用

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Linux_百度百科 (2025-12-26 12:51:52)
·Shell 流程控制 | 菜 (2025-12-26 12:51:49)
·TCP/UDP协议_百度百科 (2025-12-26 12:20:11)
·什么是TCP和UDP协议 (2025-12-26 12:20:09)
·TCP和UDP详解 (非常 (2025-12-26 12:20:06)