Linux编程经典实例.docx

上传人:牧羊曲112 文档编号:3061485 上传时间:2023-03-10 格式:DOCX 页数:9 大小:38.35KB
返回 下载 相关 举报
Linux编程经典实例.docx_第1页
第1页 / 共9页
Linux编程经典实例.docx_第2页
第2页 / 共9页
Linux编程经典实例.docx_第3页
第3页 / 共9页
Linux编程经典实例.docx_第4页
第4页 / 共9页
Linux编程经典实例.docx_第5页
第5页 / 共9页
亲,该文档总共9页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《Linux编程经典实例.docx》由会员分享,可在线阅读,更多相关《Linux编程经典实例.docx(9页珍藏版)》请在三一办公上搜索。

1、Linux编程经典实例Linux编程经典实例 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;i10;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 .+

2、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 num

3、ber: read num for (i=1;i=num;i+) do for (j=0;jnum-i;j+) do echo -n done for (j=0;j2*i-1;j+) do echo -n * done echo done for (i=1;i=num;i+) do for (j=0;ji;j+) do echo -n done for (j=0;j0; b- ) do echo $*; shift; done 8.电话本 #!/bin/bash if ! -f /root/minda then touch /root/minda fi while true echo If y

4、ou want to add a user plese type-a echo If you want to del a user plese type-d echo If you want to watch all users please type-l echo If you want to bianji users please tyye-e echo If you want to exit please type-q read b do case $b in a) echo Please type your name : read name echo Please type your

5、number : read number echo $name $number /root/minda; d) echo Please type which name do you want to del: read name cat /root/minda|grep $name /root/minda; l) cat /root/minda; e) echo Please type which name do you want to del: read name cat /root/minda|grep $name /root/minda echo Please type your new

6、name : read name echo Please type your new number : read number echo $name $number /root/minda; q) exit; esac done 9.判断当前用户的类型 #!/bin/bash case $UID in 0) echo this is root; 0-90-9) echo this is system; 1-40-90-9) echo this is service; *) echo this is public; esac 10.计算1-100的和 #!/bin/bash b=0 for (a

7、=1;a $a fi 12.用户登陆 #!/bin/bash n=1 while $n -gt 0 do echo xinjian-1 echo denglu-2 echo exit-3 read n; case $n in 1) echo username read name if -f $name then echo same username else touch /root/$name echo passwd read passwd echo $passwd /root/$name fi; 2) echo username read name1 if -f $name1 then ec

8、ho passwd else echo yonghu wrong fi read passwd1 if $passwd1 -eq cat /root/$name1 then echo success break else echo passwd wrong fi; 3) break; esac done 13.创建四个文件test1,test2,test3,test4,实现自动创建dir1,dir2,dir3,dir4四个目录,并将test1,test2,test3,test4四个文件分别拷贝到dir1,dir2,dir3,dir4相应的目录下。 #!/bin/bash for a in 1

9、2 3 4 do touch test$a mkdir dir$a cp test$a dir$a done 14.输入任意数求和./a.out 1 2 3 4 5 6 #!/bin/bash s=0 for i in $* do s=expr $s + $i done echo $s 15 函数使用 #!/bin/bash ls-a ls -al filenum=0 dirnum=0 for q in ls -a do if -d $q then dirnum=expr $dirnum + 1 fi filenum=exor $filenum + 1 done echo The number

10、 of dircetary is $dirnum echo The number of file is $filenum count s=0 while true echo .+ echo .- echo .* echo ./ echo .q echo Plz type ur word:(e.g. 1 + 1) read a b c do case $b in +) let s=a+c echo $a+$c = $s; -) let s=a-c echo $a-$c = $s; *) let s=a*c echo $a*$c = $s; /) let s=a/c echo $a/$c = $s

11、; esac case $a in q) break; esac done while true echo List Directory.ls echo List Directory -a.ls -a echo Change Directory.cd echo Back from Directory.cd. echo Edit File.vi echo Remove File.rm echo Make Directory.mkdir echo Remove Directory.rmdir echo Move File.mv echo Count.co echo PWD.pwd echo Exi

12、t Menu.q read ch do case $ch in ls) ls; ls -a)ls-a; cd) echo Enter target directory read direc cd $direc; cd.) echo Back from Direct: read file cd. $file vi) echo Enter file name read file vi $file; rm) echo enter file name read file rm $file; mkdir) echo enter dir name read file mkdir $file; rmdir) echo enter dir name read file rmdir $file; mv) echo enter file1 file2 name read f1 f2 mv $f1 $f2; co) count; pwd) pwd echo $home; q) echo cya break; esac done 总结下linux中一些入门级shell编程实例: Shell编程应用实例:

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号