linux脚本学习指南--13 函数的定义和使用及带参函数
2019-06-17 10:27
337 查看
1.简单的函数定义
#! /bin/bash
function sayhello() {
echo "Hello,World"
}
sayhello #函数调用
2.举个例子:写一个测试ngix进程是否起来,如果没有起来则手动启动nginx
检查nginx进程:ps -ef | grep nginx | grep -v grep
启动命令:systemctl start nginx
echo $? #启动完成后函数返回值为0
vi nginx_daemon.sh
#! /bin/bash
#注意当脚本名称含有nginx关键子的时候 函数返回值是有问题的
this_pid=$$ #nginx启动的编号
ps -ef | grep nginx | grep -v grep | grep -v $this_pid &> /dev/null #/dev/null 是Linux的一个无底洞
if [ $? -eq 0 ]; then # $?脚本返回值
echo "nignx is well"
else
systemtcl start nginx
echo "nginx is dowm.starting...."
fi
3.带参函数
相关文章推荐
- Python中使用函数 - 千月的python linux 系统管理指南学习笔记(4)
- Linux命令行与shell脚本(13)--在函数中使用普通变量
- 使用system()函数调用Linux脚本
- 13、进程 (shell脚本学习指南) 转
- 【mysql学习】linux安装mysql,使用install脚本方式 (二)
- Python学习:def函数的定义、使用及参数传递
- Linux-Shell脚本编程-学习-5-Shell编程-使用结构化命令-if-then-else-elif
- java学习路线__面向对象__接口的定义与使用__13
- C++学习小记(使用定义在其他.cpp文件中的变量或函数)
- java入门学习(13)—枚举类定义及使用初步
- Linux-Shell脚本编程-学习-8-函数
- linux下shell脚本的使用——安装madplay播放器,sed函数详解
- # R学习笔记5 R中函数的定义与使用
- Linux系统下shell脚本语言学习手册指南
- Linux学习笔记13——使用curses函数库
- Python学习def函数的定义、使用及参数传递
- 【Shell脚本学习13】Shell数组:shell数组的定义、数组长度
- Linux命令与shell脚本编程学习笔记-16创建函数
- linux c之使用#define定义多行函数总结
- IPython下执行shell命令-魔力函数(alias store rehash)- 千月的python linux 系统管理指南学习笔记(6)