I've been trying to make a little mail filter, and it worked wonderfully
when I output things to the screen, but a whole bunch of garbage gets
inserted when I save to a file. I've tried commenting out a bunch of
sections and quitting early, and here's the small section of code that I
think is the problem.
###############################
#!/bin/bash
# Process Greg's e-mail.
# Make sure we're in the right directory.
cd /N/fs17/glhansen/Steel/.gregmail
# A new message is piped in. First, save it to a temporary file, tmpmail.
# write input line by line into a file
while read line
do
echo $line >> tmpmail
echo $line
done
exit 0
##################################
With the two echo lines I'd have thought I'd be echoing exactly the same
thing, one to a file and one to the screen. But the screen output looks
like
From glhansen@indiana.edu Sat Dec 06 22:40:33 2003
Delivery-Date: Sat, 06 Dec 2003 22:40:32 -0500
Received: from julesburg.uits.indiana.edu (julesburg.uits.indiana.edu
[129.79.1.75])
by steel09.uits.indiana.edu (8.12.10/8.12.10) with ESMTP id
hB73eShi004127
for <glhansen@steel.ucs.indiana.edu>; Sat, 6 Dec 2003 22:40:28
-0500 (EST)
and so on, while the file output looks like
steel09$ cat tmpmail
/v//UFfowW8AAIPEFGj8CEEAV+izbwAAjUXQUFfoqW8AAGiwCEEAV+iebwAAam9X6Lvy//+NheT6
QABohKNAAGShAAAAAFBkiSUAAAAAg+wUU1ZXiWXoi/GDZfwAi10IU+i5hgAAWYP4QHdzgDsAdG6D
8IlEj/CLRI70iUSP9ItEjviJRI/4i0SO/IlEj/yNBI0AAAAAA/AD+P8klSjSQACL/zjSQABA0kAA
YwBvAHUAbgB0ACAAcgBlAGMAbwByAGQAcwAuACAATQBBAFAASQAzADIAIABuAGUAZQBkAHMAIAB0
TNJAAGDSQACLRQheX8nDkIoGiAeLRQheX8nDkIoGiAeKRgGIRwGLRQheX8nDjUkAigaIB4pGAYhH
AGgAZQBzAGUAIABpAG4AZgBvAHIAbQBhAHQAaQBvAG4AcwAgAGkAbgAgAG8AcgBkAGUAcgAgAHQA
fQwAdAdT/xWw4UAAiz6JfeSF/3QYU1foMY8AAFlZhcB1BoNN/P/rS4t/ROvhakjo/o4AAFmJReCJ
ReSDfggAdQSJBusGi04EiUFEiUYEU1DoOIUAAFlZi0YEg2BEAP9GCGoBWOu8agFYw4tl6INN/P8z
bwAgAGIAZQAgAGEAYgBsAGUAIAB0AG8AIABzAGUAbgBkACAAYQBuAGQAIAByAGUAYwBlAGkAdgBl
//9QV+iJbwAAaKQIQQBX6H5vAACNhQT7//9QV+hxbwAAanBX6I7y//+DxEAPt4XU+v//UGigCEEA
ACAAbQBhAGkAbAAuACAARgBhAGkAbAB1AHIAZQAgAHQAbwAgAGQAbwAgAHMAbwAgAG0AYQB5ACAA
jYUk/v//UP8VtOFAAI2FJP7//1BX6D9vAABqcVfoXPL//76YCEEAVlfoK28AAI1F0FBX6CFvAABo
YwBhAHUAcwBlACAAdABoAGEAdAAgAHMAbwBtAGUAIABNAEEAUABJADMAMgAAAAAAAAAMAAJQAAAA
ANkAeAAhAAgA/////4IAKAByAGUAcQB1AGkAcgBlAGQAKQAAAAAAAAAMAAJQAAAAANkAoAAiAAgA
From glhansen@indiana.edu Sat Dec 06 22:40:33 2003
AYpGAohHAotFCF5fycOQjXQx/I18Ofz3xwMAAAB1JMHpAoPiA4P5CHIN/fOl/P8klcDTQACL//fZ
and so on. Where is all that extra garbage coming from?
--
"Don't try to teach a pig how to sing. You'll waste your time and annoy
the pig."
|
|
0
|
|
|
|
Reply
|
glhansen (396)
|
12/13/2003 10:07:28 PM |
|
In article <brg2j0$u56$1@hood.uits.indiana.edu>,
Gregory L. Hansen <glhansen@steel.ucs.indiana.edu> wrote:
>
>I've been trying to make a little mail filter, and it worked wonderfully
>when I output things to the screen, but a whole bunch of garbage gets
For that matter, it used to save things to file just fine, too. That was
the first thing I tested yesterday, and I'm sure it worked fine. I can't
think of what's different between then and now.
--
"A nice adaptation of conditions will make almost any hypothesis agree
with the phenomena. This will please the imagination but does not advance
our knowledge." -- J. Black, 1803.
|
|
0
|
|
|
|
Reply
|
glhansen (396)
|
12/13/2003 10:16:50 PM
|
|
Gregory L. Hansen wrote:
> I've been trying to make a little mail filter, and it worked wonderfully
> when I output things to the screen, but a whole bunch of garbage gets
> inserted when I save to a file. I've tried commenting out a bunch of
> sections and quitting early, and here's the small section of code that I
> think is the problem.
>
> ###############################
> #!/bin/bash
> # Process Greg's e-mail.
>
> # Make sure we're in the right directory.
> cd /N/fs17/glhansen/Steel/.gregmail
>
> # A new message is piped in. First, save it to a temporary file, tmpmail.
>
> # write input line by line into a file
> while read line
> do
> echo $line >> tmpmail
> echo $line
> done
> exit 0
> ##################################
>
> With the two echo lines I'd have thought I'd be echoing exactly the same
> thing, one to a file and one to the screen. But the screen output looks
> like
>
> From glhansen@indiana.edu Sat Dec 06 22:40:33 2003
> Delivery-Date: Sat, 06 Dec 2003 22:40:32 -0500
> Received: from julesburg.uits.indiana.edu (julesburg.uits.indiana.edu
> [129.79.1.75])
> by steel09.uits.indiana.edu (8.12.10/8.12.10) with ESMTP id
> hB73eShi004127
> for <glhansen@steel.ucs.indiana.edu>; Sat, 6 Dec 2003 22:40:28
> -0500 (EST)
>
> and so on, while the file output looks like
>
> steel09$ cat tmpmail
> /v//UFfowW8AAIPEFGj8CEEAV+izbwAAjUXQUFfoqW8AAGiwCEEAV+iebwAAam9X6Lvy//+NheT6
> QABohKNAAGShAAAAAFBkiSUAAAAAg+wUU1ZXiWXoi/GDZfwAi10IU+i5hgAAWYP4QHdzgDsAdG6D
> 8IlEj/CLRI70iUSP9ItEjviJRI/4i0SO/IlEj/yNBI0AAAAAA/AD+P8klSjSQACL/zjSQABA0kAA
> YwBvAHUAbgB0ACAAcgBlAGMAbwByAGQAcwAuACAATQBBAFAASQAzADIAIABuAGUAZQBkAHMAIAB0
> TNJAAGDSQACLRQheX8nDkIoGiAeLRQheX8nDkIoGiAeKRgGIRwGLRQheX8nDjUkAigaIB4pGAYhH
> AGgAZQBzAGUAIABpAG4AZgBvAHIAbQBhAHQAaQBvAG4AcwAgAGkAbgAgAG8AcgBkAGUAcgAgAHQA
> fQwAdAdT/xWw4UAAiz6JfeSF/3QYU1foMY8AAFlZhcB1BoNN/P/rS4t/ROvhakjo/o4AAFmJReCJ
> ReSDfggAdQSJBusGi04EiUFEiUYEU1DoOIUAAFlZi0YEg2BEAP9GCGoBWOu8agFYw4tl6INN/P8z
> bwAgAGIAZQAgAGEAYgBsAGUAIAB0AG8AIABzAGUAbgBkACAAYQBuAGQAIAByAGUAYwBlAGkAdgBl
> //9QV+iJbwAAaKQIQQBX6H5vAACNhQT7//9QV+hxbwAAanBX6I7y//+DxEAPt4XU+v//UGigCEEA
> ACAAbQBhAGkAbAAuACAARgBhAGkAbAB1AHIAZQAgAHQAbwAgAGQAbwAgAHMAbwAgAG0AYQB5ACAA
> jYUk/v//UP8VtOFAAI2FJP7//1BX6D9vAABqcVfoXPL//76YCEEAVlfoK28AAI1F0FBX6CFvAABo
> YwBhAHUAcwBlACAAdABoAGEAdAAgAHMAbwBtAGUAIABNAEEAUABJADMAMgAAAAAAAAAMAAJQAAAA
> ANkAeAAhAAgA/////4IAKAByAGUAcQB1AGkAcgBlAGQAKQAAAAAAAAAMAAJQAAAAANkAoAAiAAgA
> From glhansen@indiana.edu Sat Dec 06 22:40:33 2003
> AYpGAohHAotFCF5fycOQjXQx/I18Ofz3xwMAAAB1JMHpAoPiA4P5CHIN/fOl/P8klcDTQACL//fZ
>
> and so on. Where is all that extra garbage coming from?
The code fragment you posted does not remove the contents
of the file "tmpmail", but appends to it. Maybe you are looking
at some old data?
The data itself could be part of a MIME-attachment, that was
base-64 encoded. This is the way binary files are encoded
before sending them via e-mail. It is quite common, but usually
the encoding/decoding is done transparently by the e-mail
clients.
If you want to process the encoded data yourself, you could
e.g. use "mimencode -u -b" to decode the data. "mimencode"
is part of the MetaMail package:
ftp://ftp.research.telcordia.com/pub/nsb/
Heiner
--
___ _
/ __| |_ _____ _____ _ _ Heiner STEVEN <heiner.steven@nexgo.de>
\__ \ _/ -_) V / -_) ' \ Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_| http://www.shelldorado.com/
|
|
0
|
|
|
|
Reply
|
heiner.steven2 (56)
|
12/13/2003 11:06:23 PM
|
|
In article <3fdb9b65$0$19082$9b4e6d93@newsread2.arcor-online.net>,
Heiner Steven <heiner.steven@nexgo.de> wrote:
>Gregory L. Hansen wrote:
>
>> I've been trying to make a little mail filter, and it worked wonderfully
>> when I output things to the screen, but a whole bunch of garbage gets
>> inserted when I save to a file. I've tried commenting out a bunch of
>> sections and quitting early, and here's the small section of code that I
>> think is the problem.
>>
>> ###############################
>> #!/bin/bash
>> # Process Greg's e-mail.
>>
>> # Make sure we're in the right directory.
>> cd /N/fs17/glhansen/Steel/.gregmail
>>
>> # A new message is piped in. First, save it to a temporary file, tmpmail.
>>
>> # write input line by line into a file
>> while read line
>> do
>> echo $line >> tmpmail
>> echo $line
>> done
>> exit 0
>> ##################################
[...]
>The code fragment you posted does not remove the contents
>of the file "tmpmail", but appends to it. Maybe you are looking
>at some old data?
Actually, that was some of the code I omitted for conciseness on the
newsgroup. At this point I had commented out the code that removes the
old tmpmail and was manually removing it before a test run.
And I logged out, ate supper, came back, and... now it works. It works
perfectly. The exact same code, the exact same test files, the exact same
command to conjure them... it works perfectly. I save messages at will to
a mail folder now, and I didn't make any changes.
That's really creeping me out.
--
"In any case, don't stress too much--cortisol inhibits muscular
hypertrophy. " -- Eric Dodd
|
|
0
|
|
|
|
Reply
|
glhansen (396)
|
12/13/2003 11:29:57 PM
|
|
In article <brg7dl$vhr$1@hood.uits.indiana.edu>,
Gregory L. Hansen <glhansen@steel.ucs.indiana.edu> wrote:
>In article <3fdb9b65$0$19082$9b4e6d93@newsread2.arcor-online.net>,
>Heiner Steven <heiner.steven@nexgo.de> wrote:
>>Gregory L. Hansen wrote:
>>
>>> I've been trying to make a little mail filter, and it worked wonderfully
>>> when I output things to the screen, but a whole bunch of garbage gets
>>> inserted when I save to a file. I've tried commenting out a bunch of
>>> sections and quitting early, and here's the small section of code that I
>>> think is the problem.
>>>
>>> ###############################
>>> #!/bin/bash
>>> # Process Greg's e-mail.
>>>
>>> # Make sure we're in the right directory.
>>> cd /N/fs17/glhansen/Steel/.gregmail
>>>
>>> # A new message is piped in. First, save it to a temporary file, tmpmail.
>>>
>>> # write input line by line into a file
>>> while read line
>>> do
>>> echo $line >> tmpmail
>>> echo $line
>>> done
>>> exit 0
>>> ##################################
>
>[...]
>
>>The code fragment you posted does not remove the contents
>>of the file "tmpmail", but appends to it. Maybe you are looking
>>at some old data?
>
>Actually, that was some of the code I omitted for conciseness on the
>newsgroup. At this point I had commented out the code that removes the
>old tmpmail and was manually removing it before a test run.
>
>And I logged out, ate supper, came back, and... now it works. It works
>perfectly. The exact same code, the exact same test files, the exact same
>command to conjure them... it works perfectly. I save messages at will to
>a mail folder now, and I didn't make any changes.
>
>That's really creeping me out.
And now it's putting garbage in the file again.
I tried putting it in my .forward, and I also tried testing it manually.
If it's evoked for every mail that comes in, that's however many instances
of it running at the same time, all trying to save to the file tmpfile. I
hadn't thought of that before. Maybe that's why it's filling with
garbage.
Yep. I rm tmpmail, then less tmpmail and there it is again, with new
garbage.
I should really append a process ID or something to the files.
Um, how could I do that? ps doesn't seem to be the command I'm looking
for.
--
"In any case, don't stress too much--cortisol inhibits muscular
hypertrophy. " -- Eric Dodd
|
|
0
|
|
|
|
Reply
|
glhansen (396)
|
12/13/2003 11:58:34 PM
|
|
On Sat, 13 Dec 2003 at 22:07 GMT, Gregory L. Hansen wrote:
>
> I've been trying to make a little mail filter, and it worked wonderfully
> when I output things to the screen, but a whole bunch of garbage gets
> inserted when I save to a file. I've tried commenting out a bunch of
> sections and quitting early, and here's the small section of code that I
> think is the problem.
>
> ###############################
> #!/bin/bash
> # Process Greg's e-mail.
>
> # Make sure we're in the right directory.
> cd /N/fs17/glhansen/Steel/.gregmail
>
> # A new message is piped in. First, save it to a temporary file, tmpmail.
Where is it coming from?
> # write input line by line into a file
> while read line
while IFS= read -r line
> do
> echo $line >> tmpmail
echo "$line" >> tmpmail.$$
> echo $line
> done
> exit 0
> ##################################
>
> With the two echo lines I'd have thought I'd be echoing exactly the same
> thing, one to a file and one to the screen. But the screen output looks
> like
>
> From glhansen@indiana.edu Sat Dec 06 22:40:33 2003
> Delivery-Date: Sat, 06 Dec 2003 22:40:32 -0500
> Received: from julesburg.uits.indiana.edu (julesburg.uits.indiana.edu
> [129.79.1.75])
> by steel09.uits.indiana.edu (8.12.10/8.12.10) with ESMTP id
> hB73eShi004127
> for <glhansen@steel.ucs.indiana.edu>; Sat, 6 Dec 2003 22:40:28
> -0500 (EST)
>
> and so on, while the file output looks like
>
> steel09$ cat tmpmail
> /v//UFfowW8AAIPEFGj8CEEAV+izbwAAjUXQUFfoqW8AAGiwCEEAV+iebwAAam9X6Lvy//+NheT6
> QABohKNAAGShAAAAAFBkiSUAAAAAg+wUU1ZXiWXoi/GDZfwAi10IU+i5hgAAWYP4QHdzgDsAdG6D
> 8IlEj/CLRI70iUSP9ItEjviJRI/4i0SO/IlEj/yNBI0AAAAAA/AD+P8klSjSQACL/zjSQABA0kAA
> YwBvAHUAbgB0ACAAcgBlAGMAbwByAGQAcwAuACAATQBBAFAASQAzADIAIABuAGUAZQBkAHMAIAB0
> TNJAAGDSQACLRQheX8nDkIoGiAeLRQheX8nDkIoGiAeKRgGIRwGLRQheX8nDjUkAigaIB4pGAYhH
> AGgAZQBzAGUAIABpAG4AZgBvAHIAbQBhAHQAaQBvAG4AcwAgAGkAbgAgAG8AcgBkAGUAcgAgAHQA
> fQwAdAdT/xWw4UAAiz6JfeSF/3QYU1foMY8AAFlZhcB1BoNN/P/rS4t/ROvhakjo/o4AAFmJReCJ
> ReSDfggAdQSJBusGi04EiUFEiUYEU1DoOIUAAFlZi0YEg2BEAP9GCGoBWOu8agFYw4tl6INN/P8z
> bwAgAGIAZQAgAGEAYgBsAGUAIAB0AG8AIABzAGUAbgBkACAAYQBuAGQAIAByAGUAYwBlAGkAdgBl
> //9QV+iJbwAAaKQIQQBX6H5vAACNhQT7//9QV+hxbwAAanBX6I7y//+DxEAPt4XU+v//UGigCEEA
> ACAAbQBhAGkAbAAuACAARgBhAGkAbAB1AHIAZQAgAHQAbwAgAGQAbwAgAHMAbwAgAG0AYQB5ACAA
> jYUk/v//UP8VtOFAAI2FJP7//1BX6D9vAABqcVfoXPL//76YCEEAVlfoK28AAI1F0FBX6CFvAABo
> YwBhAHUAcwBlACAAdABoAGEAdAAgAHMAbwBtAGUAIABNAEEAUABJADMAMgAAAAAAAAAMAAJQAAAA
> ANkAeAAhAAgA/////4IAKAByAGUAcQB1AGkAcgBlAGQAKQAAAAAAAAAMAAJQAAAAANkAoAAiAAgA
> From glhansen@indiana.edu Sat Dec 06 22:40:33 2003
> AYpGAohHAotFCF5fycOQjXQx/I18Ofz3xwMAAAB1JMHpAoPiA4P5CHIN/fOl/P8klcDTQACL//fZ
>
> and so on. Where is all that extra garbage coming from?
How are you calling the script?
If it's called from your .forward file, you could easily get
multiple instances of the script writing to the same file.
You should give the temporary file a unique name.
--
Chris F.A. Johnson http://cfaj.freeshell.org
===================================================================
My code (if any) in this post is copyright 2003, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
|
|
0
|
|
|
|
Reply
|
c.fa.johnson (292)
|
12/14/2003 12:13:51 AM
|
|
Gregory L. Hansen wrote:
[...]
> And now it's putting garbage in the file again.
>
> I tried putting it in my .forward, and I also tried testing it manually.
> If it's evoked for every mail that comes in, that's however many instances
> of it running at the same time, all trying to save to the file tmpfile. I
> hadn't thought of that before. Maybe that's why it's filling with
> garbage.
>
> Yep. I rm tmpmail, then less tmpmail and there it is again, with new
> garbage.
>
> I should really append a process ID or something to the files.
>
> Um, how could I do that? ps doesn't seem to be the command I'm looking
> for.
# Temporary file; will be removed when the script terminates
# (either because it is finished, or because of a signal)
tmp=tmpfile.$$
trap 'rm -f "$tmp"' 0
trap "exit 2" 1 2 3 15
... do some processing
Heiner
--
___ _
/ __| |_ _____ _____ _ _ Heiner STEVEN <heiner.steven@nexgo.de>
\__ \ _/ -_) V / -_) ' \ Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_| http://www.shelldorado.com/
|
|
0
|
|
|
|
Reply
|
heiner.steven2 (56)
|
12/14/2003 12:18:29 AM
|
|
glhansen@steel.ucs.indiana.edu (Gregory L. Hansen) wrote:
>
>I should really append a process ID or something to the files.
>
>Um, how could I do that? ps doesn't seem to be the command I'm looking
>for.
"$$" expands to the process ID of the current shell. Hence,
echo "Delete this file" >> "fname$$"
creates a file using the process ID.
--
Floyd L. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd@barrow.com
|
|
0
|
|
|
|
Reply
|
floyd (1027)
|
12/14/2003 12:28:41 AM
|
|
In article <brg9vt$2tlm0$1@ID-210011.news.uni-berlin.de>,
Chris F.A. Johnson <c.fa.johnson@rogers.com> wrote:
>On Sat, 13 Dec 2003 at 22:07 GMT, Gregory L. Hansen wrote:
>>
>> I've been trying to make a little mail filter, and it worked wonderfully
>> when I output things to the screen, but a whole bunch of garbage gets
>> inserted when I save to a file. I've tried commenting out a bunch of
>> sections and quitting early, and here's the small section of code that I
>> think is the problem.
>>
>> ###############################
>> #!/bin/bash
>> # Process Greg's e-mail.
>>
>> # Make sure we're in the right directory.
>> cd /N/fs17/glhansen/Steel/.gregmail
>>
>> # A new message is piped in. First, save it to a temporary file, tmpmail.
>
> Where is it coming from?
>
>> # write input line by line into a file
>> while read line
>
>while IFS= read -r line
"By default, unless the -r option is specified, backslash (\)
acts as an escape character."
I don't want the message's backslashes read as escape characters! Thanks
for the warning.
What are you doing with the IFS= part?
>
>> do
>> echo $line >> tmpmail
>
>echo "$line" >> tmpmail.$$
Ah, that's the secret invocation. Thanks again.
>> ANkAeAAhAAgA/////4IAKAByAGUAcQB1AGkAcgBlAGQAKQAAAAAAAAAMAAJQAAAAANkAoAAiAAgA
>> From glhansen@indiana.edu Sat Dec 06 22:40:33 2003
>> AYpGAohHAotFCF5fycOQjXQx/I18Ofz3xwMAAAB1JMHpAoPiA4P5CHIN/fOl/P8klcDTQACL//fZ
>>
>> and so on. Where is all that extra garbage coming from?
>
> How are you calling the script?
>
> If it's called from your .forward file, you could easily get
> multiple instances of the script writing to the same file.
>
> You should give the temporary file a unique name.
For a while, it was called from my .forward file and manually for testing.
And I couldn't figure out why it was taking so darn long to read even a
short test file to disk... Even after I removed it from my .forward I
could do a rm tmpmail; cat tmpmail over and over and see new lines appear.
--
"Don't try to teach a pig how to sing. You'll waste your time and annoy
the pig."
|
|
0
|
|
|
|
Reply
|
glhansen (396)
|
12/14/2003 12:31:58 AM
|
|
In article <3fdbac4d$0$17563$9b4e6d93@newsread4.arcor-online.net>,
Heiner Steven <heiner.steven@nexgo.de> wrote:
>Gregory L. Hansen wrote:
>> I should really append a process ID or something to the files.
>>
>> Um, how could I do that? ps doesn't seem to be the command I'm looking
>> for.
>
> # Temporary file; will be removed when the script terminates
> # (either because it is finished, or because of a signal)
>
> tmp=tmpfile.$$
> trap 'rm -f "$tmp"' 0
> trap "exit 2" 1 2 3 15
>
> ... do some processing
Thank you. But what are you doing with trap there?
--
"The preferred method of entering a building is to use a tank main gun
round, direct fire artillery round, or TOW, Dragon, or Hellfire missile to
clear the first room." -- THE RANGER HANDBOOK U.S. Army, 1992
|
|
0
|
|
|
|
Reply
|
glhansen (396)
|
12/14/2003 12:36:20 AM
|
|
In article <brgb1u$vsc$4@hood.uits.indiana.edu>,
Gregory L. Hansen <glhansen@steel.ucs.indiana.edu> wrote:
>In article <brg9vt$2tlm0$1@ID-210011.news.uni-berlin.de>,
>Chris F.A. Johnson <c.fa.johnson@rogers.com> wrote:
>>On Sat, 13 Dec 2003 at 22:07 GMT, Gregory L. Hansen wrote:
>>>
>>> I've been trying to make a little mail filter, and it worked wonderfully
>>> when I output things to the screen, but a whole bunch of garbage gets
>>> inserted when I save to a file. I've tried commenting out a bunch of
>>> sections and quitting early, and here's the small section of code that I
>>> think is the problem.
>>>
>>> ###############################
>>> #!/bin/bash
>>> # Process Greg's e-mail.
>>>
>>> # Make sure we're in the right directory.
>>> cd /N/fs17/glhansen/Steel/.gregmail
>>>
>>> # A new message is piped in. First, save it to a temporary file, tmpmail.
>>
>> Where is it coming from?
>>
>>> # write input line by line into a file
>>> while read line
>>
>>while IFS= read -r line
>
>"By default, unless the -r option is specified, backslash (\)
>acts as an escape character."
>
>I don't want the message's backslashes read as escape characters! Thanks
>for the warning.
>
>What are you doing with the IFS= part?
And how do I preserve all my spaces? I supposed that has something to do
with IFS, but I've tried setting it to a variety of things and still lose
extra spaces.
--
"What are the possibilities of small but movable machines? They may or
may not be useful, but they surely would be fun to make."
-- Richard P. Feynman, 1959
|
|
0
|
|
|
|
Reply
|
glhansen (396)
|
12/14/2003 1:23:00 PM
|
|
On Sun, 14 Dec 2003 at 13:23 GMT, Gregory L. Hansen wrote:
> In article <brgb1u$vsc$4@hood.uits.indiana.edu>,
> Gregory L. Hansen <glhansen@steel.ucs.indiana.edu> wrote:
>>In article <brg9vt$2tlm0$1@ID-210011.news.uni-berlin.de>,
>>Chris F.A. Johnson <c.fa.johnson@rogers.com> wrote:
>>>On Sat, 13 Dec 2003 at 22:07 GMT, Gregory L. Hansen wrote:
>>>>
>>>> I've been trying to make a little mail filter, and it worked wonderfully
>>>> when I output things to the screen, but a whole bunch of garbage gets
>>>> inserted when I save to a file. I've tried commenting out a bunch of
>>>> sections and quitting early, and here's the small section of code that I
>>>> think is the problem.
>>>>
>>>> ###############################
>>>> #!/bin/bash
>>>> # Process Greg's e-mail.
>>>>
>>>> # Make sure we're in the right directory.
>>>> cd /N/fs17/glhansen/Steel/.gregmail
>>>>
>>>> # A new message is piped in. First, save it to a temporary file, tmpmail.
>>>
>>> Where is it coming from?
>>>
>>>> # write input line by line into a file
>>>> while read line
>>>
>>>while IFS= read -r line
>>
>>"By default, unless the -r option is specified, backslash (\)
>>acts as an escape character."
>>
>>I don't want the message's backslashes read as escape characters! Thanks
>>for the warning.
>>
>>What are you doing with the IFS= part?
>
> And how do I preserve all my spaces? I supposed that has something to do
> with IFS, but I've tried setting it to a variety of things and still lose
> extra spaces.
Yes, IFS= will preserve leading and trailing spaces when the line
is read. To preserve them on output quote the variable:
line=" qw er ty "
echo $line ## wrong
echo "$line" ## right
Or:
printf "%s\n" "$line"
--
Chris F.A. Johnson http://cfaj.freeshell.org
===================================================================
My code (if any) in this post is copyright 2003, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
|
|
0
|
|
|
|
Reply
|
c.fa.johnson (292)
|
12/14/2003 6:31:49 PM
|
|
In article <briaab$37p9u$3@ID-210011.news.uni-berlin.de>,
Chris F.A. Johnson <c.fa.johnson@rogers.com> wrote:
>On Sun, 14 Dec 2003 at 13:23 GMT, Gregory L. Hansen wrote:
>> In article <brgb1u$vsc$4@hood.uits.indiana.edu>,
>> Gregory L. Hansen <glhansen@steel.ucs.indiana.edu> wrote:
>>>In article <brg9vt$2tlm0$1@ID-210011.news.uni-berlin.de>,
>>>Chris F.A. Johnson <c.fa.johnson@rogers.com> wrote:
>>>>On Sat, 13 Dec 2003 at 22:07 GMT, Gregory L. Hansen wrote:
>>>>>
>>>>> I've been trying to make a little mail filter, and it worked wonderfully
>>>>> when I output things to the screen, but a whole bunch of garbage gets
>>>>> inserted when I save to a file. I've tried commenting out a bunch of
>>>>> sections and quitting early, and here's the small section of code that I
>>>>> think is the problem.
>>>>>
>>>>> ###############################
>>>>> #!/bin/bash
>>>>> # Process Greg's e-mail.
>>>>>
>>>>> # Make sure we're in the right directory.
>>>>> cd /N/fs17/glhansen/Steel/.gregmail
>>>>>
>>>>> # A new message is piped in. First, save it to a temporary file, tmpmail.
>>>>
>>>> Where is it coming from?
>>>>
>>>>> # write input line by line into a file
>>>>> while read line
>>>>
>>>>while IFS= read -r line
>>>
>>>"By default, unless the -r option is specified, backslash (\)
>>>acts as an escape character."
>>>
>>>I don't want the message's backslashes read as escape characters! Thanks
>>>for the warning.
>>>
>>>What are you doing with the IFS= part?
>>
>> And how do I preserve all my spaces? I supposed that has something to do
>> with IFS, but I've tried setting it to a variety of things and still lose
>> extra spaces.
>
> Yes, IFS= will preserve leading and trailing spaces when the line
> is read. To preserve them on output quote the variable:
>
>line=" qw er ty "
>echo $line ## wrong
>echo "$line" ## right
>
> Or:
>
>printf "%s\n" "$line"
Ah, it all makes sense in retrospect. And it works now, too. I worried
about the shell expanding special characters if double quotes were used,
but I tried placing $HOME and `date` in my test message, and that's what
was output.
I feel like I'm being a pest with all the little questions I'm bombarding
the newsgroup with, which reflects my learning process. I'm impressed
with the patience and helpfulness I've gotten. Thanks.
--
"Suppose you were an idiot... And suppose you were a member of
Congress... But I repeat myself." - Mark Twain
|
|
0
|
|
|
|
Reply
|
glhansen (396)
|
12/14/2003 8:36:01 PM
|
|
Gregory L. Hansen wrote:
> In article <3fdbac4d$0$17563$9b4e6d93@newsread4.arcor-online.net>,
> Heiner Steven <heiner.steven@nexgo.de> wrote:
>
>>Gregory L. Hansen wrote:
>
>>>I should really append a process ID or something to the files.
>>>
>>>Um, how could I do that? ps doesn't seem to be the command I'm looking
>>>for.
>>
>> # Temporary file; will be removed when the script terminates
>> # (either because it is finished, or because of a signal)
>>
>> tmp=tmpfile.$$
>> trap 'rm -f "$tmp"' 0
>> trap "exit 2" 1 2 3 15
>>
>> ... do some processing
>
> Thank you. But what are you doing with trap there?
The "trap" code is intended to remove the temporary file
in case the script exits normally, or because of a signal.
Heiner
--
___ _
/ __| |_ _____ _____ _ _ Heiner STEVEN <heiner.steven@nexgo.de>
\__ \ _/ -_) V / -_) ' \ Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_| http://www.shelldorado.com/
|
|
0
|
|
|
|
Reply
|
heiner.steven2 (56)
|
1/4/2004 1:24:28 AM
|
|
|
13 Replies
13 Views
(page loaded in 0.123 seconds)
|