Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 1.84 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. What's wrong with my bash script to iterate over files
  2. #!/bin/bash
  3.  
  4. file="release-candidate-1.0.tar.gz"
  5. patch_base="patch-1.0."
  6. patch_extension=".tar.gz"
  7. i="1"
  8.  
  9. while [ -f $file ]
  10. do
  11.     echo $file
  12.     file="${patch_base}${i}${patch_extension}"
  13.     i=$((i+1))
  14. done
  15.        
  16. # ./script.sh
  17. file=release-candidate-1.0.tar.gz: Command not found.
  18. path_base=patch-1.0.: Command not found.
  19. patch_extension=.tar.gz: Command not found.
  20. i=1: Command not found.
  21. file: Undefined variable.
  22. #
  23.        
  24. #!/bin/bash
  25.  
  26. file="release-candidate-1.0.tar.gz"
  27. patch_bas="patch-1.0."
  28. patch_extension=".tar.gz"
  29. i="1"
  30.  
  31. while [ -f $file ]
  32. do
  33.     echo $file
  34.     file="${patch_base}${i}${patch_extension}"
  35.     i=$((i+1))
  36. done
  37.        
  38. for i in {1..10} ; do
  39.    file="${patch_base}${i}${patch_extension}"
  40.    if [ -f ${file} ] ; then
  41.       echo "Found ${file}"
  42.    else
  43.       echo "NO ${file}"
  44.    fi
  45. done
  46.        
  47. file="release-candidate-1.0.tar.gz"
  48. patch_base="patch-1.0."
  49. patch_extension=".tar.gz"
  50. i="1"
  51.        
  52. /bin/bash -vx script.sh
  53.        
  54. portsnap fetch
  55. portsnap extract update
  56. cd /usr/ports/shells/bash
  57. make install clean
  58.        
  59. #!/usr/local/bin/bash
  60.  
  61. file="release-candidate-1.0.tar.gz";
  62. patch_base="patch-1.0.";
  63. patch_extension=".tar.gz";
  64. last_patch=500;
  65. got_all_files=1;
  66.  
  67. for (( i = 0; i <= $last_patch; i++))
  68. do
  69.     if [ $i -eq 0 ]
  70.     then
  71.         if [ ! -f $file ]
  72.         then
  73.             got_all_files=0;
  74.         fi
  75.     else
  76.         file=$patch_base$i$patch_extension;
  77.         if [ ! -f $file ]
  78.         then
  79.             got_all_files=0;
  80.         fi
  81.     fi
  82. done
  83.  
  84. if [ $got_all_files -eq 0 ]
  85. then
  86.     echo "Missing files.";
  87.     exit;
  88. fi
  89.  
  90. file="release-candidate-1.0.tar.gz";
  91.  
  92. for (( i = 0; i <= $last_patch; i++))
  93. do
  94.     if [ $i -eq 0 ]
  95.     then
  96.         tar xzvpf $file
  97.         ./install.sh
  98.         ./services restart
  99.     else
  100.         file=$patch_base$i$patch_extension;
  101.         tar xzvpf $file
  102.         ./patch.sh
  103.     fi
  104. done