-->
当前位置:首页 > 题库 > 正文内容

主观题:h2.请下列shell 程序加注释,并说明程序的功能和调用方法:#!/bin/sh

Luz3年前 (2022-10-05)题库356
2.请将下列shell 程序加注释,并说明程序的功能和调用方法:#!/bin/sh

#!/bin/sh

#

# /etc/rc.d/rc.httpd

#

# Start/stop/restart the Apache web server.

#

# To make Apache start automatically at boot, make this

# file executable: chmod 755 /etc/rc.d/rc.httpd

#

case "$1" in

'start')

/usr/sbin/apachectl start ;;

'stop')

/usr/sbin/apachectl stop ;;

'restart')

/usr/sbin/apachectl restart ;;

*)

echo "usage $0 start|stop|restart" ;;

esac








答案:参考答案:

(1)程序注释

#!/bin/sh 定义实用的shell

#

# /etc/rc.d/rc.httpd 注释行,凡是以星号开始的行均为注释行。

#

# Start/stop/restart the Apache web server.

#

# To make Apache start automatically at boot, make this

# file executable: chmod 755 /etc/rc.d/rc.httpd

#

case "$1" in #case 结构开始,判断―位置参数‖决定执行的操作。本程序携带一个―位置参数‖,即$1

'start') #若位置参数为start

/usr/sbin/apachectl start ;; #启动httpd 进程

'stop') #若位置参数为stop

/usr/sbin/apachectl stop ;; #关闭httpd 进程

'restart') #若位置参数为stop

/usr/sbin/apachectl restart ;; #重新启动httpd 进程

*) #若位置参数不是start、stop 或restart 时

echo "usage $0 start|stop|restart" ;; #显示命令提示信息:程序的调用方法

esac #case 结构结束

(2)程序的功能是启动,停止或重新启动httpd 进程

(3)程序的调用方式有三种:启动,停止和重新启动。

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。