Splitting $line string into words

From thelinuxwiki
Revision as of 21:17, 26 April 2013 by Nighthawk (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

astringvar='foo bar baz'

a=( $s )

echo ${a[0]} #word0 in string

echo ${a[1]} #word1 in string

foo

bar

if parsing a file...

 cat $filename | while read line
 do
   echo "Processing new line" >/dev/tty
   for word in $line
   do
       echo $word
   done
 done