Use case: I want to pass an email message from procmail to a shell script and have the script store the Subject: header value as one variable and the Return-Path: header value.
As a test, I’m using the following script:
#!/bin/bash
while read data; do
SearchCriteria1=$(echo "$data" | grep "Subject: " | cut -c 9-)
SearchCriteria2=$(echo "$data" | grep "Return-Path: " | cut -c 13-)
echo "$SearchCriteria1" > test.1
echo "$SearchCriteria2" > test.2
done
The echo statements are just a test. I plan to use the variables later in the script.
When I try this though, test.1 and test.2 just have blank lines. I know I’m missing something obvious. Can someone please point me in the right direction?
For every line, you grep the line, leaving you either with the line or no line. Then you overwrite a file with that line (which will likely be empty most iterations). So if both those files are empty, the last line of input contains neither
Subject:orReturn-Path:.This is probably how I’d do it:
I say probably because I don’t know what the input will look like.
See also http://mywiki.wooledge.org/BashFAQ/001