BASH: cannot enter special-named dir from script
I have created some directories with exotic names, read them from script and then I try to enter them using:
cd "$i" where in i is stored ine single directory. When the directory name is dash - the script will made jump to the previous working directory. I've found in BASH manual that cd - will move you to the previus directory (from directory stack). I know how to workaround this from command line using cd \- but how can I do it from script using cd "$i"? Thank you for help. |
If I remember well you can access or list files starting with a dash with "./-myfile". In your case, it would be "./$i".
If this doesn't work, there is a thread on this forum dealing with such an access problem, but I am not able to find it now. jlinkels |
That's right. Since you don't use a full path you mean to say "in the current working directory" or "./-".
Here's an example of a check for it: Code:
function pathCheck() { [ "${i:0:1}" != "/" -a -d "$PWD/$i" ] && i="$PWD/$i"; } |
Thank you both for help, it works now correctly! :D
|
All times are GMT -5. The time now is 07:03 AM. |