shell 之 数组
函数传参使用场景示例,需求描述:写一个脚本,实现nginx服务的启动、停止、重启。 [root@shell day06]# cat nginx.sh #!/bin/bash source /etc/init.d/functions if [ $# -ne 1 ];then echo "Usage: $0 {start|stop|status|reload|restart}" exit fi rc=$1 retu() { if [ $? -eq 0 ];then action "Nginx is $rc 成功!" /bin/true else action "Nginx is $rc 失败!" /bin/false fi } start() { if [ ! -f /var/run/nginx.pid ];then /usr/sbin/nginx retu else echo "Nginx 服务正在运行....." fi } stop() { if [ -f /var/run/nginx.pid ];then /usr/sbin/nginx -s stop retu else echo "Nginx 服务不在运行......" fi } reload() { if [ -f /var/run/nginx.pid ];then /usr/sbin/nginx -s reload