I have an unknown path given by the user where I would create a file. Since I don't have write permissions I need to find the first existing dir in the path going from inside to outside and check for write permissions.
For instance foo/moo/doo
I've tried
for d in "$dirpath"/ ; do
"dir=$d"
done
But it doesn't seems to work
So I must loop trough the path whether it's absolute or relative check each node whether it exist and if it's a directory indeed and if so return it
or if not return
- perhaps top directory if the path is absolute ( not sure if there's always a concrete dir in unix on top of absolute path)
- Current directory to the relative path
Any ideas appreciate your kind help
"dir=$d"
does not do what you expect. you need to quote just the value, not the entire assignment.mkdir -p
.mkdir -p
returns "permission denied", assume there's a reason the permissions are what they are and the best your script can do is throw an error; then you investigate by hand. Any cumbersome script logic may backfire.