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

Re: Problem with arrays -- "unknown file attribute"



On Mon, Jan 05, 2009 at 09:31:31AM -0800, Webb Sprague wrote:
[...]
> > I think you should also be able to use:
> >
> >    TABS=(${(ps:\n: :)"$(sqlite3 $DB .tables)"})
> 
> Hehe... I can't say that really appeals to me in terms of grace and
> simplicity....

I don't think it works, at least not with any version of zsh I
know.

> > Either way, you'll have a problem if table names contain spaces.
> 
> I would have a bigger problem if I wrote databases with tables that
> contain spaces...  Not that it doesn't happen...
> 
> Here is the (so far) working function:
> 
> pop-colnames () {
>     local IFS=$' \t\n'    # both spaces

Or you could keep the default value of IFS which in zsh is
$' \t\n\0' (in other shells it's $' \t\n' as they don't support
the NUL character anyway).

>     setopt errreturn

You may prefer

setopt localoptions errreturn

so that the options are set locally in the variable only.


>     TABS=($(sqlite3 $DB .tables))

Note that in other shells, you would need to disable globbing as
well to avoid problems with characters like *, ? or [. You don't
need that with zsh as zsh doesn't perform filename generation
upon command substitution.

>     for TAB in $TABS; do
>         echo \"$TAB\"

Note that the echo command expands the \n, \a... sequences. You
may prefer the print -r --  or printf commands instead (or echo
-E - which is zsh specific).

>         for COL in $COLS; do
>             echo $COL
>             #sqlite3 $DB "insert into row_meta (tname, colname) values
> ($TAB, ${COL//\"/});"
>         done
>     done
> }
[...]

-- 
Stéphane



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