Distinguish directory name or path to the directory
I'm not sure what you mean, nor convinced you need to make this distinction: mkdir -- "$1"
creates a directory no matter how you present the name to it.
To test whether the first argument is a simple directory name with no path component (e.g. foo
but not foo/bar
or /abso/lute
), test whether it contains a /
:
case "$1" in */*) echo "contains multiple path components";; *) echo "no slash, just a base name";;esac
To test whether the first argument is a relative path or an absolute path, test whether it starts with /
:
case "$1" in /*) echo "absolute";; *) echo "relative";;esac
By the way that this applies whether you're considering a file or a directory.