随笔 - 21  文章 - 0  trackbacks - 0
<2014年6月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

常用链接

留言簿

随笔分类

随笔档案

文章分类

搜索

  •  

最新评论

阅读排行榜

评论排行榜



$1 compressed file
$2 dest path


function decompressandcopy()
{
    filepath=`echo $1 |  sed 's/[^\/]*$//'`   

不是/字符直到末尾,*表示可以是0

因此/PATH1/PATH2/输出也是对的



    #if filepath + tmp exist

    filetemppath=$filepath"tmp/"
    echo "filetemppath $filetemppath"


    if [ ! -d "$filetemppath" ]; then
       mkdir -p "$filetemppath"
    else
       echo "tmpfilepaht already exist: $filetemppath"
    fi

    #if exist
    if [ -d "$filetemppath" ]; then
       tar -zxvf $1 -C  $filetemppath
       if [ ! $? == 0  ]; then
          echo "tar -zxvf $filetemppath failed"
          return 1
       fi
    fi


    filelists=`ls $filetemppath`
    for tmpfile in $filelists
    do
        if [ ! "$tmpfile" == "" ]; then
           echo "move $filetemppath$tmpfile to $2 "
           mv $filetemppath$tmpfile $2
        fi
    done
}

posted on 2014-07-02 12:19 pizzx 阅读(112) 评论(0)  编辑 收藏 引用