* variables set to full lines.
@ 1998-03-01 4:34 Jason Zapman II
1998-03-01 17:35 ` Bart Schaefer
0 siblings, 1 reply; 2+ messages in thread
From: Jason Zapman II @ 1998-03-01 4:34 UTC (permalink / raw)
To: zsh-users
I've occasionally wanted to do something like this:
for line in `cat file` ; do
echo $line >> file1
done
where $line is set to a string containing each line in the file, rather
than each word.
Is there a way to do this?
Thanks;
Jason
--
Jason Price | If you want to build a ship, don't drum up people
Theta Xi, | together to collect wood and don't assign them tasks
Beta, Alpha 449 | and work, but rather teach them to long for the endless
jprice@poboxes.com | immensity of the sea. -- Antoine de Saint Exupery
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: variables set to full lines.
1998-03-01 4:34 variables set to full lines Jason Zapman II
@ 1998-03-01 17:35 ` Bart Schaefer
0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 1998-03-01 17:35 UTC (permalink / raw)
To: Jason Zapman II, zsh-users
On Feb 28, 11:34pm, Jason Zapman II wrote:
} Subject: variables set to full lines.
}
} I've occasionally wanted to do something like this:
}
} for line in `cat file` ; do
} echo $line >> file1
} done
}
} where $line is set to a string containing each line in the file, rather
} than each word.
}
} Is there a way to do this?
Depending on your requirements ...
while read line; do
echo $line >> file1
done < file
This has the drawback that stdin is redirected from "file", so if you
do something inside the loop like
rm -i $line
then when "rm" prompts for input, it also reads from "file", which is
probably not what you meant.
If you -really- want the entire contents of "file" read into the shell
all at once, this is the way to do it in 3.0.5 and 3.1.x:
for line in "${(@f)$(<file)}"; do
echo $line >> file1
done
The double-quotes are required to preserve newlines in $(<file); the (f)
splits the result into words at newlines; the (@) splits the double-quoted
string into words again.
The same basic trick works in older versions (back to 3.0.0, I think)
but you have to throw in additional ${} to get the parameter substitution
to work correctly, and you probably need a space in the $(< ); I don't
recall exactly, something like
for line in "${(@)${(f)${$(< file)}}}"; do
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1998-03-01 17:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-03-01 4:34 variables set to full lines Jason Zapman II
1998-03-01 17:35 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).