《shell脚本if..then..elif..then.if语句的总结》
第一种:
#!/bin/bash service vsftpd start &> /dev/null if
[ $? -eq 0 ]
then
echo "ftp is start"
else
service vsftpd start
fi
第二种:
#!/bin/bash read -p "input your file name " file_name
if [ -d $file_name ] //判断是否为目录
then
echo " this file is directory!"
elif [ -f $file_name ] //是否为文件
then
echo "this file is file"
elif [ -c $file_name -o -b $file_name ] //是否为字符设备或块设备,符合其一就ok
then
echo "this is block file" else echo "this file unknown"
fi
[root@redhat shellscripts]# ll /dev/sda brw-rw----. 1 root disk 8, 0 Jun 1 10:05 /dev/sda
[root@redhat shellscripts]# ll /dev/tty crw-rw-rw-. 1 root tty 5, 0 Jun 1 10:05 /dev/tty
第三种:
#!/bin/bash
if [ $# -ne 2 ]
then
echo "Not enough parameters"
exit 0 //如果不是2个数,则跳出循环
fi
if [ $1 -eq $2 ]
then
echo "$1 = $2"
elif [ $1 -lt $2 ]
then
echo "$1 < $2"
fi
执行的结果:
[root@redhat shellscripts]# sh test.sh 1 1 1 = 1
[root@redhat shellscripts]# sh test.sh 1 2 1 < 2 ~
《shell脚本if..then..elif..then.if语句的总结》的更多相关文章
- 简单物联网:外网访问内网路由器下树莓派Flask服务器
最近做一个小东西,大概过程就是想在教室,宿舍控制实验室的一些设备. 已经在树莓上搭了一个轻量的flask服务器,在实验室的路由器下,任何设备都是可以访问的:但是有一些限制条件,比如我想在宿舍控制我种花 ...
- 利用ssh反向代理以及autossh实现从外网连接内网服务器
前言 最近遇到这样一个问题,我在实验室架设了一台服务器,给师弟或者小伙伴练习Linux用,然后平时在实验室这边直接连接是没有问题的,都是内网嘛.但是回到宿舍问题出来了,使用校园网的童鞋还是能连接上,使 ...
- 外网访问内网Docker容器
外网访问内网Docker容器 本地安装了Docker容器,只能在局域网内访问,怎样从外网也能访问本地Docker容器? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动Docker容器 ...
- 外网访问内网SpringBoot
外网访问内网SpringBoot 本地安装了SpringBoot,只能在局域网内访问,怎样从外网也能访问本地SpringBoot? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装Java 1 ...
- 外网访问内网Elasticsearch WEB
外网访问内网Elasticsearch WEB 本地安装了Elasticsearch,只能在局域网内访问其WEB,怎样从外网也能访问本地Elasticsearch? 本文将介绍具体的实现步骤. 1. ...
- 怎样从外网访问内网Rails
外网访问内网Rails 本地安装了Rails,只能在局域网内访问,怎样从外网也能访问本地Rails? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动Rails 默认安装的Rails端口 ...
- 怎样从外网访问内网Memcached数据库
外网访问内网Memcached数据库 本地安装了Memcached数据库,只能在局域网内访问,怎样从外网也能访问本地Memcached数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装 ...
- 怎样从外网访问内网CouchDB数据库
外网访问内网CouchDB数据库 本地安装了CouchDB数据库,只能在局域网内访问,怎样从外网也能访问本地CouchDB数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动Cou ...
- 怎样从外网访问内网DB2数据库
外网访问内网DB2数据库 本地安装了DB2数据库,只能在局域网内访问,怎样从外网也能访问本地DB2数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动DB2数据库 默认安装的DB2 ...
- 怎样从外网访问内网OpenLDAP数据库
外网访问内网OpenLDAP数据库 本地安装了OpenLDAP数据库,只能在局域网内访问,怎样从外网也能访问本地OpenLDAP数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动 ...
随机推荐
- c#高效的线程安全队列ConcurrentQueue<T>(上)
ConcurrentQueue<T>队列是一个高效的线程安全的队列,是.Net Framework 4.0,System.Collections.Concurrent命名空间下的一个数 ...
- 关于QStringRef
QString 为字符串操作提供了各种成员比如mid().left().right().它们都创建会一个新的字符串,因此有一个对在已存在QString的malloc和深拷贝. 与此相反,QStri ...
- 关于解决 The processing instruction target matching "[xX][mM][lL]" is not allowed
在处理和保存XML文件时,出现The processing instruction target matching "[xX][mM][lL]" is not allowed 错误 ...
- Json.Net学习.集合序列化.
只要集合实现了IEnumable接口就可以进行序列化 Json序列化器为序列化及反序列化集合对象提供了良好的支持. ->Serializing 为了序列化一个集合---一个泛型的list,arr ...
- solrj:org.apache.solr.common.util.NamedList.java
package org.apache.solr.common.util; import java.io.Serializable; import java.util.ArrayList; import ...
- Amazon Launches FBA Export to Expand Beyond Media Categories
Amazon launched a new program called FBA Export for third-party sellers to help them export products ...
- 函数参数选项的处理getopt getopt_long getopt_long_only
转载:http://blog.chinaunix.net/uid-20321537-id-1966849.html 在头文件中int getopt(int argc,char *argv[], c ...
- 【MYSQL】数据类型
转载 https://www.baidu.com/s?ie=UTF-8&wd=cnblog 原文 泪云山海的博客 mysql 数据类型 1.整型 MySQL数据类型 含义(有符号) tinyi ...
- Part 9 Union and union all in sql server
Union and union all in sql server
- Swiper之滑块4
最炫3D走一波: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" ...