Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: string to array space problem in filenames

On Aug 28, 11:54am, Ray Andrews wrote:
} At this point I'm hoping for a generic answer.  Directory strings, 
} separated by spaces, are written to a file, which is then read into an 
} array and passed to 'select'

Unfortunately there are three different places where you might need to
protect the spaces.  (1) when writing to the file (2) when reading
from the file (3) when passing to select.

You've shown us one of them (more on that in a moment):

}     echo -n " $PWD" >>! ~/.mydirstack;

What about the other two steps?

Your first problem here is trying to maintain .mydirstack all as one
line (echo -n) with spaces between the fields.  You would be much
better served by writing one file name per line and then splitting
the file on newlines when reading it back.

    echo "$PWD" >>| ~/.mydirstack
    mydirstack=( ${(f)"$(<~/.mydirstack)"} )

Then you should be able to do

    select dir in "${mydirstack[@]}"; do something with $dir; done

If you insist on storing it all on one line, then you need to quote the
spaces on the way out:

    echo -n " ${(q)PWD}" >>! ~/.mydirstack;

And remove the quotes again sometime after reading it back in, but that
is where what you have told us fails to go far enough.

Messages sorted by: Reverse Date, Date, Thread, Author