<html>
<HEAD></HEAD>
<BODY>
<a href="http://c.biancheng.net/cpp/view/6994.html">-shell在线 30分钟-</a>
<br>
<FONT >û </FONT>
<br>
<textarea rows="20" cols="50">
请拷贝下面的代码 与虚拟机liunx 主文件下 命名为xxx.sh;
终端运行可以简单地输入 ./xxx.sh 就能运行了 但是可以会有问题
解决办法1:vim yyy.sh 然后 不写内容 wq 退出 chmod 777 yyy.sh 在手动拷贝 xxx.sh 到yyy.sh
再运行 ./yyy.sh 即可
更多学习,尽在菜鸟http://www.runoob.com/
</textarea><BR>
<textarea rows="50" cols="50">
#########################################################################
# File Name: XXX.sh
# Author: MZSTS.HOST.3V.COM
# mail: W22Z@QQ.com
# mail: WZASUST@163.com
# Created Time: 2016年06月26日 星期日 02时13分31秒
#########################################################################
#!/bin/
echo "wzzx"
MAX_NO=0
echo -n "Enter Number between (5 to 9) : "
echo "What is your name?"
read PERSON
echo "Hello, $PERSON"
your_name="mozhiyan"
echo $your_name
echo ${your_name}
myUrl="http://see.xidian.edu.cn/cpp/linux/"
myNum=100
variableName="value_help"
myUrl1="http://see.xidian.edu.cn/cpp/shell/"
readonly myUrl1
myUrl="http://see.xidian.edu.cn/cpp/u/xitong/"
unset myUrl
echo $myUrl
echo $$
echo "File Name: $0"
echo "First Parameter : $1"
echo "First Parameter : $2"
echo "Quoted Values: $@"
echo "Quoted Values: $*"
echo "Total Number of Parameters : $#"
echo "\$*=" $*
echo "\"\$*\"=" "$*"
echo "\$@=" $@
echo "\"\$@\"=" "$@"
echo "print each param from \$*"
for var in $*
do
echo "$var"
done
echo "print each param from \$@"
for var in $@
do
echo "$var"
done
echo "print each param from \"\$*\""
for var in "$*"
do
echo "$var"
done
echo "print each param from \"\$@\""
for var in "$@"
do
echo "$var"
done
a=10
echo -e "Value of a is $a \n"
DATE=`date`
echo "Date is $DATE"
USERS=`who | wc -l`
echo "Logged in user are $USERS"
UP=`date ; uptime`
echo "Uptime is $UP"
val=`expr 2 + 2`
echo "Total value : $val"
a=10
b=20
val=`expr $a + $b`
echo "a + b : $val"
val=`expr $a - $b`
echo "a - b : $val"
val=`expr $a \* $b`
echo "a * b : $val"
val=`expr $b / $a`
echo "b / a : $val"
val=`expr $b % $a`
echo "b % a : $val"
if [ $a == $b ]
then
echo "a is equal to b"
fi
if [ $a != $b ]
then
echo "a is not equal to b"
fi
if [ $a -eq $b ]
then
echo "$a -eq $b : a is equal to b"
else
echo "$a -eq $b: a is not equal to b"
fi
if [ $a -ne $b ]
then
echo "$a -ne $b: a is not equal to b"
else
echo "$a -ne $b : a is equal to b"
fi
if [ $a -gt $b ]
then
echo "$a -gt $b: a is greater than b"
else
echo "$a -gt $b: a is not greater than b"
fi
if [ $a -lt $b ]
then
echo "$a -lt $b: a is less than b"
else
echo "$a -lt $b: a is not less than b"
fi
if [ $a -ge $b ]
then
echo "$a -ge $b: a is greater or equal to b"
else
echo "$a -ge $b: a is not greater or equal to b"
fi
if [ $a -le $b ]
then
echo "$a -le $b: a is less or equal to b"
else
echo "$a -le $b: a is not less or equal to b"
fi
if [ $a != $b ]
then
echo "$a != $b : a is not equal to b"
else
echo "$a != $b: a is equal to b"
fi
if [ $a -lt 100 -a $b -gt 15 ]
then
echo "$a -lt 100 -a $b -gt 15 : returns true"
else
echo "$a -lt 100 -a $b -gt 15 : returns false"
fi
if [ $a -lt 100 -o $b -gt 100 ]
then
echo "$a -lt 100 -o $b -gt 100 : returns true"
else
echo "$a -lt 100 -o $b -gt 100 : returns false"
fi
if [ $a -lt 5 -o $b -gt 100 ]
then
echo "$a -lt 100 -o $b -gt 100 : returns true"
else
echo "$a -lt 100 -o $b -gt 100 : returns false"
fi
a="abc"
b="efg"
if [ $a = $b ]
then
echo "$a = $b : a is equal to b"
else
echo "$a = $b: a is not equal to b"
fi
if [ $a != $b ]
then
echo "$a != $b : a is not equal to b"
else
echo "$a != $b: a is equal to b"
fi
if [ -z $a ]
then
echo "-z $a : string length is zero"
else
echo "-z $a : string length is not zero"
fi
if [ -n $a ]
then
echo "-n $a : string length is not zero"
else
echo "-n $a : string length is zero"
fi
if [ $a ]
then
echo "$a : string is not empty"
else
echo "$a : string is empty"
fi
file="/var/www/tutorialspoint/unix/test.sh"
if [ -r $file ]
then
echo "File has read access"
else
echo "File does not have read access"
fi
if [ -w $file ]
then
echo "File has write permission"
else
echo "File does not have write permission"
fi
if [ -x $file ]
then
echo "File has execute permission"
else
echo "File does not have execute permission"
fi
if [ -f $file ]
then
echo "File is an ordinary file"
else
echo "This is sepcial file"
fi
if [ -d $file ]
then
echo "File is a directory"
else
echo "This is not a directory"
fi
if [ -s $file ]
then
echo "File size is zero"
else
echo "File size is not zero"
fi
if [ -e $file ]
then
echo "File exists"
else
echo "File does not exist"
fi
echo "sh里没有多行注释,只能每一行加一个#号"
echo "#--------------------------------------------"
echo "# 这是一个自动打ipa的脚本,基于webfrogs的ipa-build书写:"
echo "# https://github.com/webfrogs/xcode_shell/blob/master"
echo "#--------------------------------------------"
echo "##### 用户配置区 开始 #####"
echo " ##### 用户配置区 结束 #####"
echo "#-------------------test 70001 -------------------------"
your_name="qinjx"
greeting="hello, "$your_name" !"
greeting_1="hello, ${your_name} !"
echo $greeting $greeting_1
string="abcd"
echo ${#string}
string="alibaba is a great company"
echo `expr index "$string" is`
echo "#-------------------test 70002 -------------------------"
NAME[0]="Zara"
NAME[1]="Qadir"
NAME[2]="Mahnaz"
NAME[3]="Ayan"
NAME[4]="Daisy"
echo "First Index: ${NAME[0]}"
echo "Second Index: ${NAME[1]}"
echo "First Method: ${NAME[*]}"
echo "Second Method: ${NAME[@]}"
# 取得数组元素的个数
echo length=${#NAME[@]}
# 或者
echo length=${#NAME[*]}
# 取得数组单个元素的长度
echo lengthn=${#NAME[n]}
echo $n
echo lengthn=${#NAME[1]}
echo "#-------------------test 70003 echo -------------------------"
echo "OK!\c" echo "OK!\c"
echo "#------test 1499 printf--------"
printf "Hello, Shell\n"
printf "%d %s\n" 1 "abc"
# 单引号与双引号效果一样
printf '%d %s\n' 1 "abc"
# 没有引号也可以输出
printf %s abcdef
# 格式只指定了一个参数,但多出的参数仍然会按照该格式输出,format-string 被重用
printf %s abc def
printf "%s\n" abc def
printf "%s %s %s\n" a b c d e f g h i j
# 如果没有 arguments,那么 %s 用NULL代替,%d 用 0 代替
printf "%s and %d \n"
echo "#------test 7005 if else fi--------"
a=10
b=20
if [ $a == $b ]
then
echo "a is equal to b"
elif [ $a -gt $b ]
then
echo "a is greater than b"
elif [ $a -lt $b ]
then
echo "a is less than b"
else
echo "None of the condition met"
fi
echo "#------test 7005 case -------"
echo 'Input a number between 1 to 4'
echo 'Your number is:\c'
read aNum
case $aNum in
1) echo 'You select 1'
;;
2) echo 'You select 2'
;;
3) echo 'You select 3'
;;
4) echo 'You select 4'
;;
*) echo 'You do not select a number between 1 to 4'
;;
esac
echo "#------test 7007 for --------"
for loop in 1 2 3 4 5
do
echo "The value is: $loop"
done
for str in 'This is a string'
do
echo $str
done
echo "#------test 7008 while -------"
COUNTER=0
while [ $COUNTER -lt 5 ]
do
COUNTER='expr $COUNTER+1'
echo $COUNTER
done
echo "#------test 7009 until--------"
a=0
until [ ! $a -lt 10 ]
do
echo $a
a=`expr $a + 1`
done
echo "#------test 7010 break--------"
for var1 in 1 2 3
do
for var2 in 0 5
do
if [ $var1 -eq 2 -a $var2 -eq 0 ]
then
break 2
else
echo "$var1 $var2"
fi
done
done
</textarea>
<textarea rows="50" cols="50"> </textarea>
<br>
<FONT >û </FONT>
<br>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<br>
<FONT >û </FONT>
<br>
<br>
<FONT >û </FONT>
<br>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<br>
<FONT >û </FONT>
<br>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<br>
<FONT >û </FONT>
<br>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<br>
<FONT >û </FONT>
<br>
<textarea rows="50" cols="50"> </textarea><textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
<textarea rows="50" cols="50"> </textarea>
</BODY>
</html>