dirrand4 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. # Copyright © 2016, 2022 Jeffrey Cliff
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or (at
  7. # your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. # pwd
  17. let R=$RANDOM;
  18. let FILECOUNT=`ls | wc -l`;
  19. #echo "random" $R;
  20. # echo "filecount:" $FILECOUNT;
  21. if [ $FILECOUNT -eq 0 ]; then
  22. pwd
  23. fi
  24. if [ $FILECOUNT -eq 0 ]; then
  25. pwd;
  26. exit;
  27. fi
  28. let FILECOUNT=$R%$FILECOUNT;
  29. # echo $?
  30. for i in $(ls); do
  31. if [ $FILECOUNT -gt 0 ]; then
  32. let FILECOUNT-=1;
  33. else
  34. # file $i >/dev/null
  35. # echo $i
  36. cd $i 2>/dev/null
  37. if [ $? -eq 0 ]; then
  38. $0;
  39. else
  40. echo `pwd`"/"$i
  41. fi
  42. exit;
  43. fi
  44. done