4.上机题
(1)使用rpm命令进行软件的安装、删除、升级和查询。
rpm -i rpm -e rpm -u rpm -q
(2)使用yum命令进行软件的安装、删除、升级和查询。
yum install yum remove Yum search yum update
(3)使用执行Shell程序的3种方法分别执行一个Shell程序。
设该shell程序为 /study/show.sh
(1)bash /study/show.sh 或者sh /study/show.sh (2)bash < show.sh
(3)chmod a+x /study/show.sh
/study/show.sh
(4)测试某一命令的执行情况。
$?
值为0时表示为真,其余则为假
(5)使用复合结构编写一个Shell脚本程序。
#!/bin/bash
{ echo $1 echo $2 echo $3;}
(6)使用条件判断编写一个Shell脚本程序。
#!/bin/bash if [ $1 -eq 1 ];
then echo \else
echo \fi
(7)使用循环控制编写一个Shell脚本程序。
11
#! /bin/bash for i in 1 2 3 4 do
echo \第$i次\done
(8)使用无条件控制编写一个Shell脚本程序。 #! /bin/bash i=1 while true do echo $i if [ $i -eq 5 ] then break fi i=$[ i+1 ] done
(9)使用函数编写一个Shell脚本程序。 #! /bin/bash display() {
if [ $# -ne 1 ] then fi
if [ -d $1 ] then
echo 请输入 exit 1
dir $1
elif [ -f $1 ] then
cat $1
elif true then
echo 没有文件
12
}
fi
echo 请输入
display $1
(10)编写一个Shell程序,能够根据键盘输入的学生成绩,显示相应的成绩标准(分为优、良、中、差)。
#! /bin/bash while true do
if [ $1 -ge 90 ] then echo 优 break fi
if [ $1 -ge 80 ] then echo 良 break fi
if [ $1 -ge 60 ] then echo 中 break fi
if [ $1 -ge 0 ] then echo 差 break fi done
13
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库Linux张同光版课后习题答案(3)在线全文阅读。
相关推荐: