From owner-freebsd-questions@FreeBSD.ORG Tue Jun 21 15:16:58 2011 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 7C0B8106564A for ; Tue, 21 Jun 2011 15:16:58 +0000 (UTC) (envelope-from matt@conundrum.com) Received: from coke.conundrum.com (coke.conundrum.com [216.235.9.139]) by mx1.freebsd.org (Postfix) with ESMTP id 2D6538FC18 for ; Tue, 21 Jun 2011 15:16:58 +0000 (UTC) Received: from chani.conundrum.com (chani.conundrum.com [216.235.10.34]) by coke.conundrum.com (8.13.1/8.12.6) with ESMTP id p5LF0QHI054814; Tue, 21 Jun 2011 11:00:26 -0400 (EDT) (envelope-from matt@conundrum.com) From: Matthew Pounsett Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Date: Tue, 21 Jun 2011 11:00:21 -0400 To: freebsd-questions@freebsd.org Message-Id: <73E783DC-E32B-4DE3-AFF6-4A75D1D3A00A@conundrum.com> Mime-Version: 1.0 (Apple Message framework v1084) X-Mailer: Apple Mail (2.1084) Subject: sed argument processing b0rked? 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: Tue, 21 Jun 2011 15:16:58 -0000 I'm running into a weird problem with sed. I believe what I'm trying to = do should work fine, but seem to be stymied by weirdness in sed's = argument processing. This is on 8.2-RELEASE-p2. > which sed /usr/bin/sed According to years of experience and re-reading the man page five times = today this should work, however sed is treating the second -e as a file = name: > sed -i'' -e 's/^\(REVOKE ALL ON SCHEMA public FROM = \)postgres/\1pgsql/' \ ? -e 's/^\(GRANT ALL ON SCHEMA public TO \)postgres/\1pgsql/' = \ ? /tmp/pgdump sed: -e: No such file or directory If I drop the second -e it seems to work (the permission denied is = expected): > sed -i'' -e 's/^\(REVOKE ALL ON SCHEMA public FROM = \)postgres/\1pgsql/' \ ? /tmp/pgdump sed: /tmp/pgdump: Permission denied This is contrary to the sed man page: A single command may be specified as the first argument to sed. = Multiple commands may be specified by using the -e or -f options. All = commands are applied to the input in the order they are specified regardless = of their origin. I thought maybe it was an argument order problem, since -i is listed = after -e in the syntax synopsis (sometimes that matters) but that is = actually even weirder: sed -e 's/^\(REVOKE ALL ON SCHEMA public FROM \)postgres/\1pgsql/' \ -e 's/^\(GRANT ALL ON SCHEMA public TO \)postgres/\1pgsql/' \ =20= -i'' /tmp/pgdump sed: -I or -i may not be used with stdin Fiddling around some more, I found that -e can't be supplied for the = first command if there are multiple commands to be given.. but it does = work if there's only one. That doesn't seem right. sed -i'' 's/^\(REVOKE ALL ON SCHEMA public FROM \)postgres/\1pgsql/' \ -e 's/^\(GRANT ALL ON SCHEMA public TO \)postgres/\1pgsql/' = \ /tmp/pgdump sed: /tmp/pgdump: Permission denied However, that breaks again if -i is moved: > sed 's/^\(REVOKE ALL ON SCHEMA public FROM \)postgres/\1pgsql/' \ -e 's/^\(GRANT ALL ON SCHEMA public TO \)postgres/\1pgsql/' \ -i'' /tmp/pgdump sed: -e: No such file or directory sed: s/^\(GRANT ALL ON SCHEMA public TO \)postgres/\1pgsql/: No such = file or directory sed: -i: No such file or directory sed: /tmp/pgdump: Permission denied I'm fairly certain this has worked the way I'm expecting it to in the = past. After all, I wrote it this way out of habit. Either way, it = seems to me that argument processing in the current sed distributed with = the OS is broken with respect to the way it's documented. Or am I = missing something?