code_junkie

How can I get my bash script to work?

Nov 12th, 2011
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. total="0"
  4. count="0"
  5. #FILE="$1" This is the easier way
  6. for FILE in $*
  7. do
  8. # Start processing all processable files
  9. while read line
  10. do
  11. if [[ "$line" =~ ^Total ]];
  12. then
  13. tmp=$(echo $line | cut -d':' -f2)
  14. count=$(expr $count + 1)
  15. total=$(expr $total + $tmp)
  16. fi
  17. done < $FILE
  18. done
  19. echo "The Total Is: $total"
  20. echo "$FILE"
  21.  
  22. while [ $1 != "" ]
  23. do ....
  24. done
  25.  
  26. while [ "$1" != "" ]; do
  27. # Code here
  28.  
  29. # Next argument
  30. shift
  31. done
  32.  
  33. grep '^Total:' "$@" |
  34. cut -d: -f2 |
  35. awk '{sum += $1}
  36. END { print sum }'
  37.  
  38. grep "^Total:" "$@" |
  39. awk -F: '{sum += $2}
  40. END { print sum }'
  41.  
  42. awk -F: '$1 ~ /^Total/ { sum += $2 }
  43. END { print sum }' "$@"
  44.  
  45. perl -na -F: -e '$sum += $F[1] if m/^Total:/; END { print $sum; }' "$@"
  46.  
  47. while [ $# -gt 0 ]
  48. do
  49. ...process $1...
  50. shift
  51. done
  52.  
  53. #!/bin/sh
  54.  
  55. process() {
  56. echo "doing something with $1"
  57. }
  58.  
  59. for i in "$@" # Note use of "$@" to not break on filenames with whitespace
  60. do
  61. process "$i"
  62. done
  63.  
  64. while [ "$1" != "" ]; do
  65. # Code here
  66.  
  67. # Next argument
  68. shift
  69. done
Add Comment
Please, Sign In to add comment