命令替换,有两种方式

方式一:`command`

方式二:$(command)

user.sh

查找系统中所有的用户,并且输出

#!/bin/bash

nginx=`netstat -tnlp | grep  | grep nginx | wc -l`

if [ "$nginx" -gt  ];then

echo "Nginx is running..."

else

echo "Nginx is stopped"

/application/nginx/sbin/nginx

fi

weeks.sh

今年过了多少周,剩下多少周

#!/bin/bash

nginx=`netstat -tnlp | grep  | grep nginx | wc -l`

if [ "$nginx" -gt  ];then

echo "Nginx is running..."

else

echo "Nginx is stopped"

/application/nginx/sbin/nginx

fi

nginx_check.sh

nginx服务进程检查脚本,检查到nginx停止服务立即重启

#!/bin/bash

nginx=`netstat -tnlp | grep  | grep nginx | wc -l`

if [ "$nginx" -gt  ];then

echo "Nginx is running..."

else

echo "Nginx is stopped"

/application/nginx/sbin/nginx

fi

shell编程:命令替换的运用的更多相关文章

  1. Linux shell编程— 命令替换

    有两种方法可以将命令输出赋给变量 反引号字符(`) $()格式 命令替换允许你将shell 命令的输出赋给变量 要么用一对反引号把整个命令行围起来: testing=`data` 要么使用$()格式 ...

  2. shell的命令替换和命令组合

    bash&shell系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html Linux中使用反引号"``"(在波浪线的 ...

  3. 关于Shell中命令替换$(...)与后置引用`...`的不同

    命令替换 在bash中,$( )与` `(反引号)都是用来作命令替换的.命令替换与变量替换差不多,都是用来重组命令行的,先完成引号里的命令行,然后将其结果替换出来,再重组成新的命令行. $( )与`` ...

  4. 【linux】shell中命令替换$(cmd)和符号`cmd`

    来源:https://zhidao.baidu.com/question/485498670.html 作用: $(cmd)和`cmd`的作用是相同的,在执行一条命令时,会先将其中的 ``,或者是$( ...

  5. Linux shell编程命令-Linux基础环境命令学习笔记

    1.正则表达式 1)^开始 *前一个字符重复0次以上 + 1次以上 ? 0次或者1次 . 一个任意字符(.*连用) {m,n} m到n次 [0-9][a-z] 任意数字或字母 $结束字符 2)sed和 ...

  6. linux学习总结----shell编程

    ## 环境变量 ## 全局变量 ``` 常见的全局环境变量 PATH 指令的搜索路径 HOME 用户的家目录 LOGNAME 登录名 SHELL 脚本的类型 使用全局环境变量 echo $PATH 自 ...

  7. Linux编程 21 shell编程(环境变量,用户变量,命令替换)

    一.概述 这篇介绍shell的变量使用,跟其实语言一样,都有声明变量,使用变量,在shell中变量允许你临时地将信息存储中shell脚本中,以便和脚本的其他命令一起使用. 1.1 环境变量 在前面章节 ...

  8. shell编程之算术扩展(引号、命令替换、算术扩展)

    1.单引号 .双引号.反引号的区别 单引号:忽略所有特殊字符 双引号:忽略大部分特殊字符($  `等字符除外) [root@tlinux shell]# echo '*' * [root@tlinux ...

  9. Linux Shell编程(24)——命令替换

    命令替换 将会重新分配一个命令[1]甚至是多个命令的输出; 它会将命令的输出如实地添加到另一个上下文中. [2]使用命令替换的典型形式是使用后置引用(`...`). 后置引用形式的命令(就是被反引号括 ...

随机推荐

  1. StarUml3.10 Mac 注册key 破解

    /Applications/StarUML.app/Contents/Resources StarUML是用nodejs写的.确切的说是用Electron前端框架写的.新版本中所有的starUML源代 ...

  2. python3 tkinter模块小项目联系之邮箱客户端

    # -*- coding:utf-8 -*- from tkinter import * from tkinter.messagebox import askyesno, showerror, sho ...

  3. Mac中的brew

    最近要研究字体识别tesseract,才了解到brew,惭愧惭愧. 1.brew是一个软件包管理工具,类似于centos下的yum或者ubuntu下的apt-get,非常方便,免去了自己手动编译安装的 ...

  4. Codeforces 1101D 点分治

    题意:有一颗树,每个点有一个点权,边权都是1,问路径上的所有点的gcd不是1的最长路径是多少? 思路:之前补这道题的时候,用分解质因数 + 树形DP做的,其实用点分治可以更暴力一点.对于这类统计树上路 ...

  5. java输出当前文件所在路径

    System.out.println(System.getProperty("user.dir"));//user.dir指定了当前的路径

  6. Cesium经纬度

    computed: { handler() { return new this.Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas) } } ...

  7. 【leetcode】756. Pyramid Transition Matrix

    题目如下: We are stacking blocks to form a pyramid. Each block has a color which is a one letter string, ...

  8. 【leetcode】931. Minimum Falling Path Sum

    题目如下: Given a square array of integers A, we want the minimum sum of a falling path through A. A fal ...

  9. springboot 依赖

    <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot ...

  10. HTTP 错误 500.21 - Internal Server Error处理程序“NickLeeCallbackHandler”在其模块列表中有一个错误模块“ManagedPipelineHandler”

    HTTP 错误 500.21 - Internal Server Error处理程序“NickLeeCallbackHandler”在其模块列表中有一个错误模块“ManagedPipelineHand ...