#!/bin/bash

 #shell使用的熟练成都反映用户对Unix/Linux使用的熟练程度
#shell 有两种执行命令的方式:交互式和批处理
#常见的shell脚本解释器有bash,sh,csh等等
#chmod +x ./hello.sh #使脚本具有执行权限
#./hello.sh #执行脚本 #交互输入
echo "whats your name?"
read person
echo "hello,$person" #变量 定义不加$,引用要加$
myname="shiqing"
echo ${myname} #特殊变量
echo "filename:$0"
echo "first parameter:$1"
echo "second parameter:$2"
echo "all parameter:$@"
echo "all parameter:$*"
echo "total number of parameters:$#" #命令替换 ~下 `command`
USERS=`who | wc -l`
echo "Logged in user are $USERS“   #返回这个脚本文件放置的目录   cd `dirname $0`
  echo `pwd` #表达式,原生bash不支持简单的数学运算,expr 是一种表达式计算工具
val=`expr + `
echo "value is $val"
a=
b=
val=`expr $a \* $b`
echo "a * b: $val" #字符串
str="abcd"
echo ${#str}
echo ${str::} #数组
arr=(a,b,c,d)
echo "first :${arr[0]}"
echo "all:${arr[*]}" #获取所有元素
echo "length:${#arr[*]}" #获取数组长度 #if...elif...else...,条件表达式要放在方括号之间,并且要有空格
a=
b= if [ $a == $b ]
then
echo "a is equal to b"
elif [ $a -gt $b ]
then
echo "a is g reater than b"
else
echo "a is less than b"
fi #case ...easc...
echo 'Input a number between 1 to 4'
echo 'Your number is:\c'
read aNum
case $aNum in
) echo 'You select 1'
;;
) echo 'You select 2'
;;
) echo 'You select 3'
;;
) echo 'You select 4'
;;
*) echo 'You do not select a number between 1 to 4'
;;
esac #for...in...
for loop in
do
echo "The value is: $loop"
done #while...do...done...
echo 'type <CTRL-D> to terminate'
i=
while read FILM
do
echo "Yeah! great film the $FILM"
i=`expr $i + `
b=
if [ $i-gt$b ] #expression 和方括号([ ])之间必须有空格,否则会有语法错误。
then
break
fi
done #until...do...done
a=
until [ ! $a -lt ]
do
echo $a
a=`expr $a + `
val=`expr $a + $b`
done #函数
funWithParam(){
echo "The value of the first parameter is $1 !"
echo "The value of the second parameter is $2 !"
echo "The value of the tenth parameter is $10 !"
echo "The value of the tenth parameter is ${10} !"
echo "The value of the eleventh parameter is ${11} !"
echo "The amount of the parameters is $# !" # 参数个数
echo "The string of the parameters is $* !" # 传递给函数的所有参数
}
funWithParam funWithReturn(){
echo "The function is to get the sum of two numbers..."
echo -n "Input first number: "
read aNum
echo -n "Input another number: "
read anotherNum
echo "The two numbers are $aNum and $anotherNum !"
return $(($aNum+$anotherNum))
}
funWithReturn
ret=$? #函数返回值在执行函数后通过$?获得
echo "The sum of two numbers is $ret !" #输入输出重定向 >,>>(追加), <
who>users
wc -l<users

最新文章

  1. 微信浏览器是移动端的IE6?微信升级内核后Html5和CSS3兼容性总结
  2. 在实现和使用上与select和poll有很大差异
  3. 【BZOJ】1008: [HNOI2008]越狱(快速幂)
  4. App Naver Line 5.3 add new features - &quot;True Delete&quot;
  5. Android串口通信(基于Tiny6410平台)
  6. 为什么Laravel是最成功的PHP框架?
  7. 简单的闭包运算(Closure)演示程序
  8. JAVA编程思想——类型信息(反射)
  9. 对于java用发送http请求,请求内容为xml格式
  10. POJ 2114 Boatherds 划分树
  11. 【转】 完美配置Tomcat的HTTPS
  12. formidable处理node.js的post请求
  13. Springboot 系列(八)动态Banner与图片转字符图案的手动实现
  14. LOJ #556. 「Antileaf&#39;s Round」咱们去烧菜吧
  15. fft,ntt
  16. hibernate关联关系映射之配置文件
  17. 升级mac Mojave系统,git无法使用
  18. 【转】non-blocking REST services with Spring MVC
  19. __attribute__ ((attribute-list))
  20. ViewPager实现引导页(添加导航点,判断是否第一次进入主界面)

热门文章

  1. JAVA本地文本读取---解决中文乱码
  2. WebRTC 视频对话
  3. 什么是SetUID
  4. CodeVs1515 跳
  5. 汕头市队赛 SRM14 T2 最长上升子序列
  6. zmap zgrab 环境搭建
  7. kali 开启smb
  8. Mac下Lua环境搭建
  9. Visual Studio 2013下我常用的两个插件
  10. spring jpa data笔记