Guest User

Untitled

a guest
Jul 20th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #!/bin/bash
  2. dir_resolve()
  3. {
  4. cd “$1″ 2>/dev/null || return $? # cd to desired directory; if fail, quell any error messages but return exit status
  5. echo “`pwd -P`” # output full, link-resolved path
  6. }
  7.  
  8. # sample usage
  9. if abs_path=”`dir_resolve ”$1”`”
  10. then
  11. echo “$1 resolves to $abs_path”
  12. echo pwd: `pwd` # function forks subshell, so working directory outside function is not affected
  13. else
  14. echo “Could not reach $1″
  15. fi
Add Comment
Please, Sign In to add comment