Expand a possible relative path in bash
问题 As arguments to my script there are some file paths. Those can, of course, be relative (or contain ~). But for the functions I've written I need paths that are absolute, but do not have their symlinks resolved. Is there any function for this? 回答1: MY_PATH=$(readlink -f $YOUR_ARG) will resolve relative paths like "./" and "../" Consider this as well (source): #!/bin/bash dir_resolve() { cd "$1" 2>/dev/null || return $? # cd to desired directory; if fail, quell any error messages but return