I need to somehow get the output of ispell -l into an array so that I can loop through them..
So far ive got this
cat $1 | ispell -l
I have tried to read them in line by line into an array but that hasnt worked for me
any suggestions?
I need to somehow get the output of ispell -l into an array so that I can loop through them..
So far ive got this
cat $1 | ispell -l
I have tried to read them in line by line into an array but that hasnt worked for me
any suggestions?
It's actually a lot easier than any answers provided thus far. You don't need to call any external binaries such as
cat
or do any loops.Simply do:
There is no such thing as an array in shell. (Bash and zsh have array extensions; but if you find yourself thinking that a bash or a zsh extension would be helpful for a script, the correct choice is instead to rewrite in perl or python. /digression)
What you actually want is one of these constructs:
or
I would need to know more about what you're trying to do and about the output format of
ispell -l
(I don't have it installed and don't have time right now to build it) to tell you which of the above is the right option.Recent bash comes with
mapfile
orreadarray
:(this example returns effectively
ispell -l < "$1"|wc -l
)beware of the mistake to do e.g.
ls | readarray
, it won't work because readarray would be in a subshell because of the pipe. Use input redirection only.you can pipe the result of
ispell
toawk
Awk
has better performance for iterating through files than the shell.