shell简单练习
来源:互联网 发布:局域网斗地主软件 编辑:程序博客网 时间:2024/06/06 15:37
求1~100的和
#!/bin/bash
#下面两行是声明主要的环境变量,这样可以让这个程序在运行时可以直接执行一些外部命令,而不必写绝对路径。
PATH=/bin:/sbin:/usr/bin:usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
s=0 #注意这里,等号两边不能有空格
i=0
while ["$i" != "100"] #判断符号[ ]
do
i=$(($i+1))#无类型变量参与运算
s=$(($s+$i))
done
echo "the result is ===> $s" //输出
用下面的程序认识shell的默认变量
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
echo "the script name is ==> $0"
echo "total parameter number is ==> $#" #所有参数个数
#注意下面的方括号与表达式要有空格
[ "$#" -lt 2 ] && echo "too few parameter,stop here." && exit 0
echo "the whole parameter is ==> '$@'" #所有参数
echo "the 1st parameter is ==> $1"
echo "the 2nd parameter is ==> $2"
输入命令sh test.sh one two three
有如下结果:
the script name is ==> test.sh
total parameter number is ==> 3
the whole parameter is ==> 'one two three'
the 1st parameter is ==> one
the 2nd parameter is ==> two
其他程序,待续。。。
- shell简单练习
- Shell脚本简单练习
- shell脚本的简单练习
- 简单的shell脚本练习
- 第十三章 简单的 shell script 练习
- shell练习
- shell练习
- shell 练习
- shell练习
- shell练习
- shell 练习
- shell 练习
- shell练习
- shell练习
- shell -- 练习
- 【shell脚本练习】网卡信息和简单日志分析
- shell编程练习
- shell 脚本练习。笔记
- liunx 下配置mysql的问题
- project euler problem 12
- C专家编程--指针和数组(三) 值传递 指针传递 引用传递
- JS之函数定义的三种方式
- for 循环执行顺序
- shell简单练习
- 查看、修改oracle字符集,查看oracle版本
- log4j配置说明
- C专家编程--指针和数组(四) 指针对数组的访问
- 会话跟踪技术
- sql nvarchar为null问题
- (1.1.6)UVA 10978 Let's Play Magic!(直叙式模拟)
- dm368ipnc 重写架构中的swosd 实现中文osd
- CRC5的verilog实现(X5+X2+X0)