Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- dir_resolve()
- {
- cd “$1″ 2>/dev/null || return $? # cd to desired directory; if fail, quell any error messages but return exit status
- echo “`pwd -P`” # output full, link-resolved path
- }
- # sample usage
- if abs_path=”`dir_resolve ”$1”`”
- then
- echo “$1 resolves to $abs_path”
- echo pwd: `pwd` # function forks subshell, so working directory outside function is not affected
- else
- echo “Could not reach $1″
- fi
Add Comment
Please, Sign In to add comment