Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Problem with arrays -- "unknown file attribute"
- X-seq: zsh-users 13646
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: Webb Sprague <webb.sprague@xxxxxxxxx>
- Subject: Re: Problem with arrays -- "unknown file attribute"
- Date: Mon, 5 Jan 2009 18:17:32 +0000
- Cc: gak@xxxxxxxxxxxxxx, zsh-users@xxxxxxxxxx
- In-reply-to: <b11ea23c0901050931q790f8804tdbc8807c0c51a086@xxxxxxxxxxxxxx>
- Mail-followup-to: Webb Sprague <webb.sprague@xxxxxxxxx>, gak@xxxxxxxxxxxxxx, zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <b11ea23c0901050004h4f1825egc01d39c1f74c0ef0@xxxxxxxxxxxxxx> <alpine.LNX.2.00.0901050308270.17470@xxxxxxxxxxxxxxx> <20090105092403.GA7733@xxxxxxxxxxxxxxx> <alpine.LNX.2.00.0901050426390.17470@xxxxxxxxxxxxxxx> <m3fxjxenta.fsf@xxxxxxxxxxxxxx> <b11ea23c0901050931q790f8804tdbc8807c0c51a086@xxxxxxxxxxxxxx>
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