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

Re: BUG? - 4.0.2 - parameter substitution won't double backslashes in values



Derek Peschel wrote:

> I want to write the elements of $dirstack out to a file, separated by
> newlines.  If an element in $dirstack contains a newline, I want to write
> a backslash before the newline in the file.  Parameter substitution
> managed that:

If what you're really after is being able to dump the value of
$dirstack to a file to be able to restore it from that file later, you
could just use some trickery:

  dump_dirstack() {
    print -lr 'dirstack=(' "${(q@)dirstack}" ')' > ~/.dirstack
  }

  # pretty useless wrapper function...

  restore_dirstack() {
    . ~/.dirstack
  }

Or some such.

A generic function to store an array (1st arg) to a file (2nd arg)
would be:

  dump_array() {
    print -lr "$1=(" "${(P@q)1}" ')' > $2
  }

Hope that helps...


Bye
  Sven

-- 
Sven Wischnowsky                          wischnow@xxxxxxxxx



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