-   Programming (
-   -   BASH: cannot enter special-named dir from script (

Roger Krowiak 08-24-2006 05:00 AM

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.

jlinkels 08-24-2006 06:10 AM

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.


unSpawn 08-24-2006 06:14 AM

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:

function pathCheck() { [ "${i:0:1}" != "/" -a -d "$PWD/$i" ] && i="$PWD/$i"; }

Roger Krowiak 08-24-2006 06:19 AM

Thank you both for help, it works now correctly! :D

All times are GMT -5. The time now is 11:10 AM.