分类:
2010-12-06 19:43:23
#!/bin/sh
#echo something
echo "hello world"
echo "hello !!"
mkdir /tnt
#!/bin/sh
#set varible a
a="hello world"
#print a
echo "A is:"
echo $a
#!/bin/sh
#set varible num
num=2
echo "this is the ${num}nd"
#!/bin/sh
echo "number of vars:"$#
echo "values of vars:"$*
echo "value of var1:"$1
echo "value of var2:"$2
echo "value of var3:"$3
echo "value of var4:"$4
#!/bin/sh
hello="var1"
echo $hello
function func1 {
local hello="var2"
echo $hello
}
func1
echo $hello
#!/bin/sh
folder=/home
[ -r "$folder" ] && echo "Can read $folder"
[ -f "$folder" ] || echo "this is not file"
#!/bin/bash
for day in Sun Mon Tue Wed Thu Fri Sat
do
echo $day
done
#!/bin/bash
for day in "Sun Mon Tue Wed Thu Fri Sat"
do
echo $day
done
#!/bin/bash
echo "Hit a key, then hit return."
read Keypress
case "$Keypress" in
[A-Z] ) echo "Uppercase letter";;
[a-z] ) echo "Lowercase letter";;
[0-9] ) echo "Digit";;
* ) echo "Punctuation, whitespace, or other";;
esac
两数进行比较
#!/bin/sh
a=$1
b=$2
if [ -z $1 ] || [ -z $2 ]
then
echo "please enter 2 no"
exit 1
fi
if [ $a -eq $b ];then
echo "a=b"
else if [ $a -gt $b ]
then
echo "a>b"
elif [ $a -lt $b ]
then
echo "a
fi
fi
计算当前目录下文件的个数
#!/bin/sh
counter=0
for files in *
do
if [ -f "$files" ]
then
counter='expr $counter + 1'
fi
done
echo "there are $counter files in 'pwd'"
倒序输出
#!/bin/sh
echo -n "please enter number"
read n
sd=0
rev=""
on=$n
echo "you put number is $n"
while [ $n -gt 0 ]
do
sd=$(($n % 10))
n=$(($n / 10))
rev="$rev$sd"
done
echo "$on is a reverse order $rev"
文件监视
#!/bin/sh
if [ "$1" = "" ]||[ "$2" = "" ]
then
echo "please enter file name"
exit 1
fi
if [ -e $2 ]
then
echo "the file already exists"
until [ ! -f $2 ]
do
sleep 1
done
echo "the file have been deleted"
fi
if [ !'mv $1 $2' ]
then
echo "mv sucessful"
else
echo "error"
fi