自己在ubuntu 14.04上面试了一些
#!/bin/bash
num=20
num1=30
num2=35
num3=90
str1=jack
str2=pony
:<<!
#调用函数
source func.sh
func
#func.sh为一个文件,里面写了一个函数,内容如下:
#!/bin/bash
function func()
{
echo this is a function
}
if [ $num1 -lt $num2 -a $num2 -gt $num3 ] #-a 与 -o 或 ! 非
then
echo "11111111"
else
echo "222222222"
fi
#或
if [[ $num1 -lt $num2 && $num2 -gt $num3 ]] #&& ||
then
echo "&&&&&&&&&"
else
echo "|||||||||"
fi
#case使用
case $num in
1)
echo 1
;;
2)
echo 2
;;
10)
echo 10
;;
*)
echo something else
;;
esac
while [ $num -lt 10 ]
do
echo $num
let num++ #要用bash运行,否则会报let not found,因为默认shell为dash
done
if [ $num -lt $num2 ]
then
echo num2 is large than num
else
echo num2 is less than num
fi
if [ -z $str1 ]
then
echo str1 is empty
else
echo str1 is not empty
fi
!
#for i in 1 2 3 4 5 6 7 8 9
#do
# echo $num
#done
#echo "this is the ${num}nd"
#echo $PATH
读写输入一个值,字符串,数组等操作参考下面链接:
参考链接:http://blog.csdn.net/u011204847/article/details/51184883
原文链接:https://www.f2er.com/bash/389261.html