Advertisement
GangBoss

Untitled

Dec 11th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [[ "$1" = -h || "$1" = —help ]]
  4. then
  5. echo "Usage: clearPath.sh [path]"
  6. echo.
  7. echo The script displays the directories names with executable files.
  8. echo If [path] is empty script displays the directories names PATH
  9. exit 0
  10. fi
  11.  
  12. if [ -z "$1" ]
  13. then
  14. currentPath="$PATH"
  15. else
  16. currentPath="$1"
  17. fi
  18.  
  19. LFS=':'
  20. result=""
  21. echo $currentPath
  22. echo ""
  23. for folder in $currentPath
  24. do
  25. echo "$folder"
  26. if [[ ! -d "$folder" || "$result": == *:$(readlink -f "$folder"):* ]]
  27. then
  28.  
  29. continue
  30. fi
  31. firstChar=$(echo "$folder" | cut -c 1)
  32. if [[ "$firstChar" == "." || "$firstChar" == "~" ]]
  33. then
  34. continue
  35. fi
  36. for file in $folder
  37. do
  38. if [[ -x "$file" ]]
  39. then
  40. result=$result:$(readlink -f "$folder")
  41. break
  42. fi
  43. done
  44. done
  45. IFS=' '
  46. echo "${result#:}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement