SHARE
TWEET

get relative path example

tolikpunkoff Jun 2nd, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. #get relative path example
  4. #start path: /tmp/test/dir1/subidr1/startpoint
  5. #end path: /tmp/test/dir2/subdir2/endpoint
  6.  
  7. START="/tmp/test/dir1/subidr1/startpoint"
  8. END="/tmp/test/dir2/subdir2/endpoint"
  9.  
  10. mkdir -p "$START"
  11. mkdir -p "$END"
  12.  
  13. cd "$START"
  14. echo -n "Start directory:"
  15. pwd
  16.  
  17. RP=`realpath --relative-to="$START" "$END"`
  18. echo "Relative path: $RP"
  19.  
  20. echo "CD to relative path:"
  21. cd "$RP"
  22.  
  23. echo -n "End directory:"
  24. pwd
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top