1.一个简单的hello world例子
#!bin/bash
echo "hello wolrd"
2.shell变量
基本的赋值方式:name="XXX"。注意等号两边都不能带有空格,否则出现错误;字符串必须用引号括起。
3.shell输入
#!bin/bash
echo "please input your name and age"
read name age
echo "your name is "$name
echo "your age is "$age
4.shell数组
http://bbs.chinaunix.net/thread-1779167-1-1.html
5. if 控制语句
#!/bin/bash
echo "please input your name"
read name
if test -n name
then
echo "your name is "$name
else
echo "name is null"
fi
#!/bin/bash
echo "please input num A and B"
read a b
if test $a -lt $b
then
echo "a < b"
elif test $a -gt $b
then
echo "a > b"
else
echo "a = b"
fi
6. case语句
#!/bin/bash
echo "please input your name"
read name
case $name in
tom)
echo "hello tom";;
jane)
echo "hello jane";;
*)
echo "I don‘t know your name";;
esac
#!/bin/bash
for i in 1 2 3 4 5 6 7
do
echo $i
done
#!/bin/sh
i=1
while test $i -lt 5
do
echo $i
i=${{$i+1}}
done
原文:http://blog.csdn.net/wanghao109/article/details/21157297