Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #init path
  4. if [[ -z "$1" ]]
  5. then
  6. path=$PATH
  7. else
  8. path=$1
  9. fi
  10.  
  11. newPath=""
  12.  
  13. if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]
  14. then
  15. echo This script is clearing PATH directory
  16. exit 0;
  17. fi
  18.  
  19. IFS=":" read -ra h<<<"$path"
  20. for i in "${h[@]}"; do
  21. if [ -d "$1" ]
  22. then
  23. for path in $(find "$i" -maxdepth 1 -type f -executable)
  24. do
  25. if ((${#newPath} == 0 ))
  26. then
  27. newPath=$i
  28. elif [[ $newPath != *"$i"* ]]
  29. then
  30. newPath=$newPath":"$i
  31. fi
  32. done
  33. fi
  34. done
  35.  
  36. echo "$newPath"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement