[EMAIL PROTECTED] wrote:
>               The problem is that if I did this out of the box
>               like the following, it 'flattens' the list:
>
>               Example:
>                       for j in `cat $i`; do
>                               echo $j
>                       done
>
>               Output:
>                       This
>                       is
>                       a
>                       file
>                       [...]

Inserting quotes into the output of the command substitution won't
help.  Quotes are given special syntactic status only if they are
unquoted themselves, and do not appear as the result of any kind of
expansion.

You can use a "while read" loop as Chet suggested, or you can tell
bash to split the `cat` expansion only at newlines, not as other
whitespace:
  old_ifs=$IFS
  IFS=$'\n'
  for j in `cat "$i"`; do
    ...
  done
  IFS=$old_ifs

If you have other unquoted expansions within the body of the for loop
that should use the normal IFS for splitting, then you'll have to
restore the original IFS after splitting `cat`, but before entering the
for loop:
  old_ifs=$IFS
  IFS=$'\n'
  set x `cat "$i"`
  shift
  IFS=$old_ifs
  for j in "$@"; do
    ...
  done


paul


_______________________________________________
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash

Reply via email to