#!/bin/bash
#defind the path
PATH=/usr/local
export PATH
read -p "please input your first name:" firstname
reap -p "please input your last name:" lastname
echo -e "\nyour name is: $firstname $lastname" #use date create file
read -p "please input your filename:" fileuser
filename=${fileuser:-"filename"}
#use date get the filename
date1=$(date --date='2 days ago' +%Y%m%d)
date2=$(date --date='1 days ago' +%Y%m%d)
date3=$(date +%Y%m%d)
file1=${filename}${date1}
file2=${filename}${date2}
file3=${filename}${date3}
touch "$file1"
touch "$file2"
touch "$file3" #条件判断式
read -p "please input (Y/N): " yn
if [ "$yn"=="Y" ] || [ "$yn"=="y" ] ; then
echo "OK continue"
exit
fi
if [ "$yn"=="N" ] || [ "$yn"=="n" ] ; then
echo "OK continue"
exit
fi
#第二种情况
if [条件判断式]; then
内容
else
内容
fi
#三
if [条件判断式]; then
内容
elif [条件判断式]; then
内容
else
内容
fi #利用case...esac判断
case $变量名称 in
"第一个变量内容")
程序段
;;
"第二个变量内容")
程序段
;;
*)
程序段(不包含第一和第二个变量内容中的)
exit
;;
esac #举例
case $ in
"one")
echo "This is one"
;;
"two")
echo "this is two"
;;
"three")
echo "This is three"
;;
*)
echo "no number"
;;
esac #利用function功能(shell script执行方式是 由上而下,由左至右,所以function函数一定要写在程序的最前边) function printit(){
echo -n "Your choice is "
}

shell-script的简单举例的更多相关文章

  1. shell script的简单使用

    shell script的简单介绍 shell变量 1.命名规则 命名只能使用英文字母,数字和下划线,首个字符不能以数字开头 中间不能有空格,可以使用下划线(_) 不能使用标点符号. 不能使用bash ...

  2. shell script 的简单介绍

    一 什么叫shell script (程序化脚本)? shell script 是利用 shell 的功能所写的一个 “程序”(program),这个程序是使用纯文本文件,将一些 shell 的语法与 ...

  3. 第十三章、学习 Shell Scripts 简单的 shell script 练习

    简单的 shell script 练习 简单范例 对谈式脚本:变量内容由使用者决定 [root@www scripts]# vi sh02.sh #!/bin/bash # Program: # Us ...

  4. shell script简单笔记

    变量 shell script是一种脚本语言,变量的定义是通过 myName=HYB 这样的形式定义的. 当存在空格时,可以通过双引号或单引号将其变为字符串.双引号不进行转义,单引号将内容进行转义为一 ...

  5. 第13章 学习shell script

    由于博客园中dollar符号有别的意义,所以文中的dollar符号使用¥表示 第一个script [root@localhost script]# cat -n sh01.sh #!/bin/bash ...

  6. 这些年我们一起搞过的持续集成~Jenkins+Perl and Shell script

    这些年我们一起搞过的持续集成~Jenkins+Perl and Shell script ##转载注明出处:http://www.cnblogs.com/wade-xu/p/4378224.html ...

  7. shell script入门

    从程序员的角度来看, Shell本身是一种用C语言编写的程序,从用户的角度来看,Shell是用户与Linux操作系统沟通的桥梁.用户既可以输入命令执行,又可以利用 Shell脚本编程,完成更加复杂的操 ...

  8. shell script 的追踪与 debug

    shell script 的追踪与 debug scripts 在运行之前,最怕的就是出现语法错误的问题了!那么我们如何 debug 呢?有没有办法不需要透过直接运行该 scripts 就可以来判断是 ...

  9. linux基础之Shell Script入门介绍

    本文介绍下,学习shell script编程的入门知识,通过几个入门实例,带领大家走进shell script的神圣殿堂,呵呵,有需要的朋友参考下. 本文转自:http://www.jbxue.com ...

随机推荐

  1. Jquery事件

    在JS里加事件  <input type="button" value="测试" onclick="test()"/>跟一个函数 ...

  2. MVC5 网站开发之三 数据存储层功能实现

    数据存储层在项目Ninesky.DataLibrary中实现,整个项目只有一个类Repository.   目录 奔跑吧,代码小哥! MVC5网站开发之一 总体概述 MVC5 网站开发之二 创建项目 ...

  3. ASP.NET Core中的依赖注入(4): 构造函数的选择与服务生命周期管理

    ServiceProvider最终提供的服务实例都是根据对应的ServiceDescriptor创建的,对于一个具体的ServiceDescriptor对象来说,如果它的ImplementationI ...

  4. spring aop

    什么是AOP AOP(Aspect-OrientedProgramming,面向方面编程),它利用一种称为“横切”的技术,剖解开封装的对象内部,并将那些影响了多个类的公共行为封装到一个可重用模块,并将 ...

  5. Python(六)面向对象、异常处理、反射、单例模式

    本章内容: 创建类和对象 面向对象三大特性(封装.继承.多态) 类的成员(字段.方法.属性) 类成员的修饰符(公有.私有) 类的特殊成员 isinstance(obj, cls) & issu ...

  6. ASP.NET Core 介绍

    原文:Introduction to ASP.NET Core 作者:Daniel Roth.Rick Anderson.Shaun Luttin 翻译:江振宇(Kerry Jiang) 校对:许登洋 ...

  7. Java进击C#——应用开发之WinForm开发

    本章简言 上一章笔者介绍了关于WinForm环境.这一章笔者将继续讲WinForm.只不过更加的面向开发了.事实就是在学习工具箱里面的控件.对于WinForm开发来讲,企业对他的要求并没有那么高.但是 ...

  8. Basic Tutorials of Redis(5) - Sorted Set

    The last post is mainly about the unsorted set,in this post I will show you the sorted set playing a ...

  9. WPF's Style BasedOn

    <Style x:Key="BasedStyle" BasedOn="{x:Null}" TargetType="{x:Type Control ...

  10. .net 一些开源的东东

    来自网络..版权归网络所有..Antlr ----- Website: http://www.antlr.org/ Copyright: Copyright (c) - Terence Parr Li ...