shell脚本实例Word格式.docx

上传人:b****1 文档编号:1359423 上传时间:2023-04-30 格式:DOCX 页数:13 大小:21.37KB
下载 相关 举报
shell脚本实例Word格式.docx_第1页
第1页 / 共13页
shell脚本实例Word格式.docx_第2页
第2页 / 共13页
shell脚本实例Word格式.docx_第3页
第3页 / 共13页
shell脚本实例Word格式.docx_第4页
第4页 / 共13页
shell脚本实例Word格式.docx_第5页
第5页 / 共13页
shell脚本实例Word格式.docx_第6页
第6页 / 共13页
shell脚本实例Word格式.docx_第7页
第7页 / 共13页
shell脚本实例Word格式.docx_第8页
第8页 / 共13页
shell脚本实例Word格式.docx_第9页
第9页 / 共13页
shell脚本实例Word格式.docx_第10页
第10页 / 共13页
shell脚本实例Word格式.docx_第11页
第11页 / 共13页
shell脚本实例Word格式.docx_第12页
第12页 / 共13页
shell脚本实例Word格式.docx_第13页
第13页 / 共13页
亲,该文档总共13页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

shell脚本实例Word格式.docx

《shell脚本实例Word格式.docx》由会员分享,可在线阅读,更多相关《shell脚本实例Word格式.docx(13页珍藏版)》请在冰点文库上搜索。

shell脚本实例Word格式.docx

==>

$(whoami)"

3.echo 

The 

current 

directory 

`pwd`"

#请自行建立一支程式,该程式可以用来计算『您还有几天可以过生日』啊?

2.read 

-p 

Pleas 

input 

your 

birthday 

(MMDD, 

ex>

0709):

bir 

3.now=`date 

+%m%d` 

4.if 

$bir"

== 

$now"

];

then 

5.echo 

Happy 

Birthday 

to 

you!

!

6.elif 

-gt 

7.year=`date 

+%Y` 

8.total_d=$(($((`date 

--date="

$year$bir"

+%s`-`date 

+%s`))/60/60/24)) 

9.echo 

will 

be 

$total_d 

later"

10.else 

11.year=$((`date 

+%Y`+1)) 

12.total_d=$(($((`date 

13.echo 

14.fi 

#让使用者输入一个数字,程式可以由1+2+3...一直累加到使用者输入的数字为止。

Please 

an 

integer 

number:

number 

3.i=0 

4.s=0 

5.while 

$i"

$number"

6.do 

7.i=$(($i+1)) 

8.s=$(($s+$i)) 

9.done 

10.echo 

the 

result 

of 

'

1+2+3+...$number'

$s"

#撰写一支程式,他的作用是:

1.)先查看一下/root/test/logical这个名称是否存在;

2.)若不存在,则建立一个档案,使用touch来建立,建立完成后离开;

3.)如果存在的话,判断该名称是否为档案,若为档案则将之删除后建立一个档案,档名为logical,之后离开;

4.)如果存在的话,而且该名称为目录,则移除此目录!

2.if 

logical 

3.touch 

4.echo 

Just 

make 

file 

logical"

5.exit 

&

-f 

7.rm 

8.mkdir 

remove 

and 

11.exit 

12.elif 

-d 

13.rm 

-rf 

14.echo 

15.exit 

16.else 

17.echo 

Does 

here 

have 

anything?

18.fi 

#我们知道/etc/passwd里面以:

来分隔,第一栏为帐号名称。

请写一苹程式,可以将/etc/passwd的第一栏取出,而且每一栏都以一行字串『The1accountis"

root"

』来显示,那个1表示行数。

2.accounts=`cat 

/etc/passwd 

cut 

-d'

:

-f1` 

3.for 

account 

in 

$accounts 

4.do 

5.declare 

-i 

i=$i+1 

6.echo 

$i 

/"

$account/"

7.done 

来自:

1.写一个脚本,利用循环计算10的阶乘

/bin/sh 

2. 

3.factorial=1 

4. 

5.for 

`seq 

10` 

7. 

factorial=`expr 

$factorial 

/* 

$a` 

8.done 

9. 

10!

$factorial"

上面有一行,forain`seq110`,其中seq110,即列出现1到10之间所有的数字,这一行也可改为:

forain"

12345678910"

2.写一个脚本,执行后,打印一行提示“Pleaseinputanumber:

,要求用户输入数值,然后打印出该数值,

然后再次要求用户输入数值。

直到用户输入"

end"

停止。

3.unset 

var 

$var"

echo 

-n 

please 

8. 

read 

if 

10. 

11. 

break 

12. 

fi 

13. 

14.done 

3.写一个脚本,利用循环和continue关键字,计算100以内能被3整除的数之和

2.sum=0 

100` 

5. 

`expr 

$a 

3` 

-ne 

6. 

continue 

sum=`expr 

$sum 

11.done 

12.echo 

sum 

$sum"

4.一个函数,利用shift计算所有参数乘积,假设参数均为整数(特殊变量$#表示包含参数的个数)

3.result=1 

4.while 

$# 

5.do 

result=`expr 

$result 

$1` 

shift 

$resul 

5.写一个脚本,可以根据参数文件名,以正确的参数调用tar来解压缩tar.gz或tar.bz2文件。

3.case 

${1##*.tar.} 

bz2) 

tar 

jxvf 

$1 

;

gz) 

zxvf 

*) 

wrong 

type"

12.esac 

6.写一个脚本以方便用户查询rpm的相关信息。

这个脚本首先提示用户选择查询依据,比如

文件名,包名,全部等。

然后提示用户选择查询信息,比如包名,包里所包含的所有文件,

包的信息等。

然后询问是否继续查询,是则循环刚才的过程,否则退出。

2.RPM=/bin/rpm 

3.option="

-q"

true 

what 

query?

select 

All"

file"

package 

name"

do 

case 

$var 

All) 

option=$option"

a"

14. 

15. 

file) 

16. 

name:

17. 

f"

18. 

argument 

19. 

20. 

21. 

package/ 

name) 

22. 

23. 

24. 

25. 

26. 

27. 

choose 

between 

1-3"

28. 

29. 

esac 

30. 

done 

31. 

32. 

you 

want 

know?

33. 

location"

info"

34. 

35. 

36. 

location) 

37. 

l"

38. 

39. 

40. 

info) 

41. 

i"

42. 

43. 

44. 

45. 

46. 

47. 

48. 

49. 

50. 

51. 

52. 

53. 

${RPM} 

$option 

$argument 

54. 

55. 

continue?

[yes/no]"

56. 

answer 

57. 

58. 

no"

59. 

60. 

61. 

62.done 

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

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2