About
This article is about the path management in bash. ie /dir/childDir/fileName.
How to
get the name of the file
basename $path
from relative to absolute
MYPATH="../whatever"
MYPATH=$(readlink -f ${MYPATH})
to relative
relative_path="${fullPathDir#$baseDir}"
is Absolute
if [[ "$PATH" = /* ]]; then
echo "absolute path";
else
echo "relative path";
fi
case $PATH in
/*) echo "absolute path" ;;
*) echo "relative path" ;;
esac
from Windows to Linux and vice-versa
cygpath -u path # from Windows to Linux
cygpath path # from Linux to Windows
File or Directory
if [[ -d ${ARG} ]]; then
echo "${ARG} is a directory";
elif [[ -f ${ARG} ]]; then
echo "${ARG} is a file";
else
echo "${ARG} is not a path";
exit 1;
fi