From owner-freebsd-questions@FreeBSD.ORG Sat Jun 27 13:13:14 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9921D1065675 for ; Sat, 27 Jun 2009 13:13:14 +0000 (UTC) (envelope-from zhangweiwu@realss.com) Received: from bossdog.realss.com (bossdog.realss.com [211.157.114.130]) by mx1.freebsd.org (Postfix) with ESMTP id 0D6178FC12 for ; Sat, 27 Jun 2009 13:13:13 +0000 (UTC) (envelope-from zhangweiwu@realss.com) Received: from localhost (unknown [127.0.0.1]) by bossdog.realss.com (Postfix) with ESMTP id D12041C00CF for ; Sat, 27 Jun 2009 20:49:59 +0800 (CST) Received: from bossdog.realss.com ([127.0.0.1]) by localhost (bossdog.realss.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 08205-05 for ; Sat, 27 Jun 2009 20:49:57 +0800 (CST) Received: from [192.168.1.118] (unknown [123.116.122.130]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by bossdog.realss.com (Postfix) with ESMTP id AEEC41C00CE for ; Sat, 27 Jun 2009 20:49:57 +0800 (CST) Message-ID: <4A461551.7090702@realss.com> Date: Sat, 27 Jun 2009 20:49:21 +0800 From: Zhang Weiwu User-Agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103) MIME-Version: 1.0 To: FreeBSD Questions mailing list X-Enigmail-Version: 0.95.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Virus-Scanned: amavisd-new at bossdog.realss.com Subject: scripting suggestion: how to make this command shorter X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Jun 2009 13:13:14 -0000 Hello. I wrote this one-line command to fetch a page from a long uri, parse it twice: first time get subject & second time get content, and send it as email to me. $ w3m -dump 'http://search1.taobao.com/browse/33/n-g,w6y4zzjaxxymvjomxy----------------40--commend-0-all-33.htm?at_topsearch=1&ssid=e-s5' | grep -A 100 对比 | mail -a 'Content-Type: text/plain; charset=UTF-8' -s '=?UTF-8?B?'`w3m -dump 'http://search1.taobao.com/browse/33/n-g,w6y4zzjaxxymvjomxy----------------40--commend-0-all-33.htm?at_topsearch=1&ssid=e-s5' | grep 找到.*件 | base64 -w0`'?=' zhangweiwu@realss.com The stupid part of this script is it fetches the page 2 times and parse 2 times, thus making the command very long. If I can write the command in a way that the URI only appear once, then it is easier for me to maintain it. I plan to put it in cron yet avoid having to modify two places when the URI changes (and it does!). How do you suggest optimizing the one-liner? By the way I feel it stupid having to wrap the subject by using: $ mail -s '=?UTF-8?B?'`echo $subject | base64`'?=' instead of $ mail -s $subject Because mail(1), as defined, intelligent user agent, should know the current locale is UTF-8 and should know UTF-8 header must be base64 encoded for RFC compatibility. Yet it also should know if mail body is UTF-8 the header 'Content-Type: text/plain; charset=UTF-8' must not be omitted in case of UTF-8 content. I think this is a bug, as both are required by RFC. How do you think?