Shell程序荟萃
--------------纯输出----------------1.sh
#!/bin/sh
echo -e "Hello!world!\a\n"
exit 0
--------------获得用户输入----------------2.sh
#!/bin/sh
read -p "Please input your name:" name
echo -e "\nHello!$name"
exit 0
--------------日期计算昨天今天明天----------------3.sh
#!/bin/sh
yesterday=$(date --date='1 days ago' +%Y/%m/%d)
today=$(date +%Y%m%d)
tomorrow=$(date -d '1 days' +%Y-%m-%d)
echo -e "Yesterday is $yesterday"
echo -e "Today is $today"
echo -e "Tomorrow is $tomorrow"
exit 0
--------------100以内加减法计算游戏----------------4.sh
#!/bin/sh
declare -i rnd1=$RANDOM
declare -i rnd2=$RANDOM
op1=$(( $rnd1%100 ))
op2=$(( $rnd2%100 ))
if [ $op2 -gt $op1 ]; then
op3=$op2
op2=$op1
op1=$op3
fi
op4=$(( $op1%2 ))
if [ $op4 == 1 ]; then
result=$(( $op1+$op2 ))
read -p "$op1+$op2=" resp
if [ $result == $resp ]; then
echo " v"
else
echo " x"
fi
else
result=$(( $op1-$op2 ))
read -p "$op1-$op2=" resp
if [ $result == $resp ]; then
echo " v"
else
echo " x"
fi
fi
exit 0
--------------待续----------------
Shell程序荟萃的更多相关文章
- linux shell程序
shell程序介绍 1.查看我们的Linux(centos6.5为例)有多少我们可以使用的shell: [root@localhost bin]# cat /etc/shells /bin/sh /b ...
- Linux shell程序一
设计一个Shell程序,在/$HONE/test目录下建立50个目录,即user1-user50, 并设置每个目录的权限,其中其他用户的权限为:读:文件所有者的权限为: 读.写.执行:文件所有者所在组 ...
- 工作中一个简单的shell程序
下面是工作中用到的链接数据库的shell程序. #!/bin/bash ] ; then echo "prase is wrong ,please check first" exi ...
- 学习Shell脚本编程(第4期)_在Shell程序中的使用变量
变量的赋值 变量的访问 变量的输入 4.1 变量的赋值 在Shell编程中,所有的变量名都由字符串组成,并且不需要对变量进行声明.要赋值给一个变量,其格式如下: 变量名=值 注意: 等号(= ...
- 学习Shell脚本编程(第3期)_在Shell程序中使用的参数
位置参数 内部参数 如同ls命令可以接受目录等作为它的参数一样,在Shell编程时同样可以使用参数.Shell程序中的参数分为位置参数和内部参数等. 3.1 位置参数 由系统提供的参数称为位置参数.位 ...
- 学习Shell脚本编程(第2期)_编写修改权限及执行Shell程序的步骤
编写Shell程序 执行Shell程序 Shell程序有很多类似C语言和其他程序设计语言的特征,但是又没有程序语言那样复杂.Shell程序是指放在一个文件中的一系列Linux命令和实用程序.在执行的时 ...
- Linux shell编程02 shell程序的执行 及文件权限
第一个shell脚本 1. shell编程的方式 交互式shell编程 非交互式shell编程:执行的语句存放到一个文件 shell脚本:可以任意文件名,建议扩展名为sh 2. ...
- Linux系统学习笔记之 1 一个简单的shell程序
不看笔记,长时间不用自己都忘了,还是得经常看看笔记啊. 一个简单的shell程序 shell结构 1.#!指定执行脚本的shell 2.#注释行 3.命令和控制结构 创建shell程序的步骤 第一步: ...
- Linux Shell 之 我的第一个Shell程序
这里我首先会介绍一个Shell是什么,再介绍我的第一个Shell程序和从中总结的经验. 一.Shell是什么 在说我的这个Shell程序之前,还是先跟大家说说什么是Shell吧,相信Shell这个 ...
随机推荐
- 命令神器:lsof 常用
lsof -i 显示所有网络连接lsof -i 6 获取IPv6信息lsof -itcp 显示tcp连接lsof -i:80 显示指定端口信息lsof -i@172.12.5.6 显示指定ip连接ls ...
- Shell 学习笔记之条件语句
条件语句 if # if if condition then command fi # if else if condition then command else command fi # if e ...
- 读书笔记_Effective_C++_条款三十三:避免遮掩继承而来的名称
名称的遮掩可以分成变量的遮掩与函数的遮掩两类,本质都是名字的查找方式导致的,当编译器要去查找一个名字时,它一旦找到一个相符的名字,就不会再往下去找了,因此遮掩本质上是优先查找哪个名字的问题. 而查找是 ...
- ROS知识(20)----使用Master_API查询Master管理的节点话题服务内容
在一些应用中会需要获取master的uri地址,发布的话题,订阅的话题,发布的服务,节点的信息等等.这些功能我们通常可一通过rosnode list, rosnode info, rostopic l ...
- A* search算法解迷宫
这是一个使用A* search算法解迷宫的问题,细节请看:http://www.laurentluce.com/posts/solving-mazes-using-python-simple-recu ...
- phpcms功能列表
上1 站点首页 就是前台首页 会员中心 跳到会员中心页面 搜索 新闻,图片等文档搜索 锁屏 锁住账号 Phpcms 官网 授权 官网查询 支持论坛 官网论坛 帮助 官网帮助 上2 我的面板 个人信息 ...
- HDU 4726 Kia's Calculation(贪心)
Kia's Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- perf 工具介绍1
https://perf.wiki.kernel.org/index.php/Tutorial http://os.51cto.com/art/201105/265133.htm 在LINUX 源代码 ...
- Error : The specified component was not reported by the VSS writer (Error 517) in Windows Server 2012 Backup
Error : The specified component was not reported by the VSS writer (Error 517) in Windows Server 201 ...
- Oracle 11g 错误:ORA-28002: the password will expire within 7 days 解决方法
ERROR:ORA-28002: the password will expire within 7 days 错误是提示password快过期了,有两个办法解决问题. 一. 改动已经报错用户的pas ...