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

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



On Mon, 5 Jan 2009, Stephane Chazelas wrote:

On Mon, Jan 05, 2009 at 03:27:24AM -0500, Benjamin R. Haskell wrote:

The following should work:

...
TABS=( ${=$(sqlite3 $DB .tables)} )
for TAB in $TABS ; do
...

${=...} turns on SH_WORD_SPLIT. And, I think the parentheses around $TABS
was the cause of the odd error message.
[...]

word splitting is only on for command substitution, it only for parameter expansion that you need = to enable it.

Ah, thanks. I jumped the gun.


Here, you want:

IFS=$'\n'
TABS=($(sqlite3 $DB .tables))

or

TABS=(${(f)"$(sqlite3 $DB .tables)"})


The ${(f)"$(command stuff)"} idiom is especially useful in general. But, in this case, neither of these works, since sqlite3 returns multiple tables per line:

$ TABS=($(sqlite3 ~mozprof/formhistory.sqlite .tables)) ; print -l $TABS
moz_dummy_table  moz_formhistory
$ TABS=(${(f)"$(sqlite3 ~mozprof/formhistory.sqlite .tables)"}) ; print -l $TABS
moz_dummy_table  moz_formhistory
$ unset IFS
$ TABS=($(sqlite3 ~mozprof/formhistory.sqlite .tables)) ; print -l $TABS
moz_dummy_table
moz_formhistory
$

Best,
Ben



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