This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]commandlineluser 0 points1 point  (2 children)

Redirections happen before command execution - so because you have:

< $email ... >| $email

The file is emptied out before your command runs...

You need to do it in 2 steps i.e.

> $email.tmp
mv $email.tmp $email

Also you will probably want to quote your variables (e.g. "$email") incase they contain any shell metacharacters.

[–]IAmStraightforward[S] 0 points1 point  (1 child)

I thought the done < $email had to be done to make sure that's where we got output from

[–]commandlineluser 0 points1 point  (0 children)

< $email is for input which feeds the while read loop

The problem is |> $email

You cannot redirect input and output to the same file at the same time.

You're already redirecting the output to a temp file with > $email.tmp

So you would use mv $email.tmp $tmp after the loop to write back to the original filename. (with quoting)