MakeTestFile 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/sh
  2. # create a test pattern to check SD Card reading
  3. usage()
  4. {
  5. [ -z "$1" ] || echo error: $*
  6. echo usage: $(basename "$0") '[--verbose] [--overwrite] filename length'
  7. echo ' filename = name of file to create, cannot already exist'
  8. echo ' length = size (kBytes) to create'
  9. exit 1
  10. }
  11. verbose=0
  12. overwrite=0
  13. while :
  14. do
  15. case "$1" in
  16. --verbose)
  17. verbose=1
  18. shift
  19. ;;
  20. --overwrite)
  21. overwrite=1
  22. shift
  23. ;;
  24. --help)
  25. usage
  26. ;;
  27. -*)
  28. usage invalid option
  29. ;;
  30. *)
  31. break
  32. ;;
  33. esac
  34. done
  35. filename="$1"; shift
  36. [ -z "${filename}" ] && usage missing filename
  37. [ 1 -eq ${overwrite} ] && rm -f "${filename}"
  38. [ -e "${filename}" ] && usage file, ${filename} already exists
  39. length="$1"; shift
  40. [ -z "${length}" ] && usage missing length
  41. [ 0 -eq ${length} ] && usage length cannot be zero
  42. awk '
  43. BEGIN {
  44. BlockCount = '"${length}"'
  45. pattern = ""
  46. for (i = 0; i < 1024; ++i)
  47. {
  48. pattern = pattern sprintf("%c", i)
  49. }
  50. for (block = 0; block < BlockCount; ++block)
  51. {
  52. printf "%s", pattern
  53. }
  54. }' > "${filename}"