百度首页 | 百度空间
 
查看文章
 
shell学习二
2008-02-28 14:33

filename=12121212123
if [ ! -e "$filename" ]
    then
    echo "File $filename not found."

fi

-----------------------------------------------

NUMBERS="9 7 3 8 37.53"
for number in $NUMBERS
do
   echo -n "$number"
   echo
done

-------------------------------------------------

执行10次的循环

LIMIT=10
a=1
while [ "$a" -le "$LIMIT" ]
do
    echo -n "$a"
    let "a+=1"
done

------------------------------------------------

continue实例

LIMIT=19
echo
echo "Printing Numbers 1 through 20 (but not 3 and 11)."
a=0
while [ $a -le "$LIMIT" ]
do
a=$(($a+1))
if [ "$a" -eq 3 ] || [ "$a" -eq 11 ]
then
   continue
fi
echo -n "$a "
done

===========================

if [ ! -d "$dir" ]
then
       echo "$dir is not a directory"
else  
       rm -f "$dir"/*
fi

删除一个目录下的所有文件

============================

tar -cvf filename.tar temp.1204165816 temp.1204165945 file22.txt

tar -tvf filename.tar 要列出 tar 文件的内容,键入:

tar cvf - `find . -mtime -1 -type f -print` > $BACKUPFILE.tar

---------------------------------------------------------------------------

变量替换

b=`ls -l`echo "$b"

n=$(cat now)
echo $b
echo $n

----------------------------------------------------------------------------

uname -a 显示全部的信息。

uname -n 示在网络上的主机名称

uname -s 显示操作系统名称。

uname -v 显示操作系统版本


类别:Shell | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码:
 

     

©2008 Baidu