Chinaunix首页 | 论坛 | 博客
  • 博客访问: 416403
  • 博文数量: 73
  • 博客积分: 3326
  • 博客等级: 中校
  • 技术积分: 631
  • 用 户 组: 普通用户
  • 注册时间: 2010-02-05 15:31
文章分类

全部博文(73)

文章存档

2014年(1)

2011年(51)

2010年(21)

分类: LINUX

2011-07-20 20:51:20

  1. #!/bin/bash
  2. ##for file zip and unzip
  3. #date:2011/7/20  

  4. #input:current_filename
  5. #use gunzip\bzip\tar commands to do this .
  6. #two choices:pack||unpack

  7. pack()
  8. {
  9. ##use tar cmd to pack file
  10. echo "Now will use tar to pack the file......"
  11. echo "tar $CUR_FILE ......."
  12. #sleep 1
  13. tar -zcvf $CUR_FILE.tar.gz $CUR_FILE
  14. if [ "$?" -eq "0" ];then
  15. echo "pack file $CUR_FILE into tar.gz file ok~!"
  16. else
  17. echo "Error:Pack file into tar.gz failed~!"
  18. exit 1
  19. fi
  20. }

  21. unpack(){
  22. ##get file type
  23. ftype=`file $CUR_FILE`
  24. #echo file type
  25. echo "Your file type is:###$ftype"
  26. case "$ftype" in
  27. "$CUR_FILE: Zip archive"*)
  28. unzip $CUR_FILE
  29. echo "unzip $CUR_FILE OK~!"
  30. ;;
  31. "$CUR_FILE: gzip compressed"*)
  32. gunzip $CUR_FILE 
  33. echo "gunzip $CUR_FILE OK~!"
  34. ;;
  35. "$CUR_FILE: bzip2 compressed"*)
  36. bunzip2 $CUR_FILE 
  37. echo "bunzip $CUR_FILE OK~!"
  38. ;;
  39. *) 
  40. echo "File $CUR_FILE can not be uncompressed!!!"
  41. exit 1
  42. ;;
  43. esac

  44. }

  45. CUR_FILE="$1"
  46. if [ -z $CUR_FILE];then
  47. echo "Please input your filename!"
  48. exit 1
  49. else
  50. echo "Your file name:$CUR_FILE"

  51. ##make target choice
  52. echo "Which work you wanna do?"
  53. select var in "pack" "unpack";do
  54. break
  55. done
  56. echo "You selected $var file....."

  57. case $var in
  58. pack)
  59. pack CUR_FILE
  60. ;;
  61.      unpack)
  62. unpack CUR_FILE
  63. ;;
  64. *)
  65. echo "Usage:select option error!"
  66. exit 1
  67. esac
  68. fi
阅读(5336) | 评论(0) | 转发(0) |
0

上一篇:cscope install&&use

下一篇:bash的内部命令

给主人留下些什么吧!~~