From debbugs-submit-bounces@debbugs.gnu.org Wed Dec 09 20:08:15 2015 Received: (at submit) by debbugs.gnu.org; 10 Dec 2015 01:08:15 +0000 Received: from localhost ([127.0.0.1]:38313 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1a6piR-0007o9-Bi for submit@debbugs.gnu.org; Wed, 09 Dec 2015 20:08:15 -0500 Received: from eggs.gnu.org ([208.118.235.92]:50505) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1a6pcA-0007ZB-8E for submit@debbugs.gnu.org; Wed, 09 Dec 2015 20:01:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a6iaW-0006KF-SU for submit@debbugs.gnu.org; Wed, 09 Dec 2015 12:31:37 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:45188) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a6iaW-0006KB-QI for submit@debbugs.gnu.org; Wed, 09 Dec 2015 12:31:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33743) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a6iaW-0002uP-0l for bug-coreutils@gnu.org; Wed, 09 Dec 2015 12:31:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a6iaR-0006JG-2S for bug-coreutils@gnu.org; Wed, 09 Dec 2015 12:31:35 -0500 Received: from usa7109mr009.acs-inc.com ([13.28.230.20]:19639) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a6iaQ-0006HD-Us for bug-coreutils@gnu.org; Wed, 09 Dec 2015 12:31:31 -0500 Received: from usa7109ht004.na.xerox.net ([13.41.230.30]) by USA7109MR009.ACS-INC.COM with ESMTP/TLS/AES128-SHA; 09 Dec 2015 11:31:23 -0600 Received: from USA7109MB022.na.xerox.net ([169.254.6.149]) by USA7109HT004.na.xerox.net ([13.41.230.30]) with mapi id 14.03.0224.002; Wed, 9 Dec 2015 11:31:23 -0600 From: "Nellis, Kenneth" To: "bug-coreutils@gnu.org" Subject: dirname enhancement Thread-Topic: dirname enhancement Thread-Index: AdEypohWxQeTL2lqQz6bwSyckoTMCw== Date: Wed, 9 Dec 2015 17:31:23 +0000 Message-ID: <0D835E9B9CD07F40A48423F80D3B5A702E9D277D@USA7109MB022.na.xerox.net> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [13.41.230.95] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Wed, 09 Dec 2015 20:08:14 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) I frequently need to extract the `dirname's from a list of files, so dirname should have an option to take its input from a file, e.g.: dirname -f where could be "-" for stdin. E.g., to get a list of directories that contain a specific file:=20 find -name "xyz.dat" | dirname -f - The same would be good for `basename' as well. --Ken Nellis From debbugs-submit-bounces@debbugs.gnu.org Wed Dec 09 20:46:22 2015 Received: (at 22128) by debbugs.gnu.org; 10 Dec 2015 01:46:22 +0000 Received: from localhost ([127.0.0.1]:38458 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1a6qJK-00026D-Dk for submit@debbugs.gnu.org; Wed, 09 Dec 2015 20:46:22 -0500 Received: from mail1.vodafone.ie ([213.233.128.43]:21342) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1a6qJI-000260-Tf for 22128@debbugs.gnu.org; Wed, 09 Dec 2015 20:46:21 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AksFAO7YaFZtTKfl/2dsb2JhbABegmlRhCO8QoYPAoErTAEBAQEBAYELhDQBAQEDARIgAUsLCw0LCRYPCQMCAQIBRQYBDAgBAR6IBQyjJZAYjCEBLIVahXmJQAWNLYk8ln6TSWOEBD6GLQEBAQ Received: from unknown (HELO localhost.localdomain) ([109.76.167.229]) by mail1.vodafone.ie with ESMTP; 10 Dec 2015 01:45:43 +0000 Subject: Re: bug#22128: dirname enhancement To: "Nellis, Kenneth" , 22128@debbugs.gnu.org References: <0D835E9B9CD07F40A48423F80D3B5A702E9D277D@USA7109MB022.na.xerox.net> From: =?UTF-8?Q?P=c3=a1draig_Brady?= X-Enigmail-Draft-Status: N1110 Message-ID: <5668D947.8080801@draigBrady.com> Date: Thu, 10 Dec 2015 01:45:43 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <0D835E9B9CD07F40A48423F80D3B5A702E9D277D@USA7109MB022.na.xerox.net> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 22128 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) tag 22128 notabug close 22128 stop On 09/12/15 17:31, Nellis, Kenneth wrote: > I frequently need to extract the `dirname's from a list of files, > so dirname should have an option to take its input from a > file, e.g.: > > dirname -f xargs dirname < filename > where could be "-" for stdin. > > E.g., to get a list of directories that contain a specific > file: > > find -name "xyz.dat" | dirname -f - find -name "xyz.dat" -print0 | xargs -r0 dirname > The same would be good for `basename' as well. xargs basename -a < filename thanks, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Thu Dec 10 11:34:13 2015 Received: (at 22128) by debbugs.gnu.org; 10 Dec 2015 16:34:13 +0000 Received: from localhost ([127.0.0.1]:39286 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1a74AW-0000lP-VW for submit@debbugs.gnu.org; Thu, 10 Dec 2015 11:34:13 -0500 Received: from havoc.proulx.com ([96.88.95.61]:43310) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1a74AW-0000lI-76 for 22128@debbugs.gnu.org; Thu, 10 Dec 2015 11:34:12 -0500 Received: from joseki.proulx.com (localhost [127.0.0.1]) by havoc.proulx.com (Postfix) with ESMTP id 6191B85; Thu, 10 Dec 2015 09:34:11 -0700 (MST) Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id EEC5F2183B; Thu, 10 Dec 2015 09:34:10 -0700 (MST) Received: by hysteria.proulx.com (Postfix, from userid 1000) id D0A182DC41; Thu, 10 Dec 2015 09:34:10 -0700 (MST) Date: Thu, 10 Dec 2015 09:34:10 -0700 From: Bob Proulx To: "Nellis, Kenneth" , 22128@debbugs.gnu.org Subject: Re: bug#22128: dirname enhancement Message-ID: <20151210092752873175265@bob.proulx.com> References: <0D835E9B9CD07F40A48423F80D3B5A702E9D277D@USA7109MB022.na.xerox.net> <5668D947.8080801@draigBrady.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5668D947.8080801@draigBrady.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 22128 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Pádraig Brady wrote: > Nellis, Kenneth wrote: > > E.g., to get a list of directories that contain a specific file: > > > > find -name "xyz.dat" | dirname -f - > > find -name "xyz.dat" -print0 | xargs -r0 dirname Also if using GNU find can use GNU find's -printf operand and %h to print the directory of the matching item. Not portable to non-gnu systems. find . -name xyz.dat -printf "%h\n" Can generate null terminated string output for further xargs -0 use. find . -name xyz.dat -printf "%h\0" | xargs -0 ...otherstuff... Bob From debbugs-submit-bounces@debbugs.gnu.org Thu Dec 10 11:49:30 2015 Received: (at 22128) by debbugs.gnu.org; 10 Dec 2015 16:49:30 +0000 Received: from localhost ([127.0.0.1]:39301 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1a74PK-000179-FX for submit@debbugs.gnu.org; Thu, 10 Dec 2015 11:49:30 -0500 Received: from usa7109mr001.acs-inc.com ([13.28.230.12]:42318) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1a74PH-00016y-1E for 22128@debbugs.gnu.org; Thu, 10 Dec 2015 11:49:29 -0500 Received: from usa7109ht003.na.xerox.net ([13.41.230.29]) by USA7109MR001.ACS-INC.COM with ESMTP/TLS/AES128-SHA; 10 Dec 2015 10:49:26 -0600 Received: from USA7109MB022.na.xerox.net ([169.254.6.149]) by USA7109HT003.na.xerox.net ([13.41.230.29]) with mapi id 14.03.0224.002; Thu, 10 Dec 2015 10:49:24 -0600 From: "Nellis, Kenneth" To: Bob Proulx , "22128@debbugs.gnu.org" <22128@debbugs.gnu.org> Subject: RE: bug#22128: dirname enhancement Thread-Topic: bug#22128: dirname enhancement Thread-Index: AdEypohWxQeTL2lqQz6bwSyckoTMCwAeD1mAAB8HXQAADIH7oA== Date: Thu, 10 Dec 2015 16:49:24 +0000 Message-ID: <0D835E9B9CD07F40A48423F80D3B5A702E9D2AC7@USA7109MB022.na.xerox.net> References: <0D835E9B9CD07F40A48423F80D3B5A702E9D277D@USA7109MB022.na.xerox.net> <5668D947.8080801@draigBrady.com> <20151210092752873175265@bob.proulx.com> In-Reply-To: <20151210092752873175265@bob.proulx.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [13.41.230.95] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 22128 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) Thanx. Hadn't yet discovered GNU find's -printf option. Still, my -f suggestion would be easier to type, but I welcome your alternatives. -Ken > -----Original Message----- > From: Bob Proulx [mailto:bob@proulx.com] > Sent: Thursday, December 10, 2015 11:34 AM > To: Nellis, Kenneth; 22128@debbugs.gnu.org > Subject: Re: bug#22128: dirname enhancement >=20 > P=E1draig Brady wrote: > > Nellis, Kenneth wrote: > > > E.g., to get a list of directories that contain a specific file: > > > > > > find -name "xyz.dat" | dirname -f - > > > > find -name "xyz.dat" -print0 | xargs -r0 dirname >=20 > Also if using GNU find can use GNU find's -printf operand and %h to > print the directory of the matching item. Not portable to non-gnu > systems. >=20 > find . -name xyz.dat -printf "%h\n" >=20 > Can generate null terminated string output for further xargs -0 use. >=20 > find . -name xyz.dat -printf "%h\0" | xargs -0 ...otherstuff... >=20 > Bob From debbugs-submit-bounces@debbugs.gnu.org Thu Dec 10 12:40:34 2015 Received: (at 22128) by debbugs.gnu.org; 10 Dec 2015 17:40:34 +0000 Received: from localhost ([127.0.0.1]:39362 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1a75Ck-0002Mw-9N for submit@debbugs.gnu.org; Thu, 10 Dec 2015 12:40:34 -0500 Received: from havoc.proulx.com ([96.88.95.61]:43982) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1a75Ch-0002Ml-Qm for 22128@debbugs.gnu.org; Thu, 10 Dec 2015 12:40:32 -0500 Received: from joseki.proulx.com (localhost [127.0.0.1]) by havoc.proulx.com (Postfix) with ESMTP id C942D19EC; Thu, 10 Dec 2015 10:40:30 -0700 (MST) Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id 62D6C2183B; Thu, 10 Dec 2015 10:40:30 -0700 (MST) Received: by hysteria.proulx.com (Postfix, from userid 1000) id 3828D2DBC1; Thu, 10 Dec 2015 10:40:30 -0700 (MST) Date: Thu, 10 Dec 2015 10:40:30 -0700 From: Bob Proulx To: "Nellis, Kenneth" Subject: Re: bug#22128: dirname enhancement Message-ID: <20151210101835772207404@bob.proulx.com> References: <0D835E9B9CD07F40A48423F80D3B5A702E9D277D@USA7109MB022.na.xerox.net> <5668D947.8080801@draigBrady.com> <20151210092752873175265@bob.proulx.com> <0D835E9B9CD07F40A48423F80D3B5A702E9D2AC7@USA7109MB022.na.xerox.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <0D835E9B9CD07F40A48423F80D3B5A702E9D2AC7@USA7109MB022.na.xerox.net> User-Agent: Mutt/1.5.24 (2015-08-30) X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 22128 Cc: "22128@debbugs.gnu.org" <22128@debbugs.gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Nellis, Kenneth wrote: > Still, my -f suggestion would be easier to type, > but I welcome your alternatives. Here is the problem. You would like dirname to read a list from a file. Someone else will want it to read a file list of files listing files. Another will want to skip one header line. Another will want to skip multiple header lines. Another will want the exact same feature in basename too. Another will want file name modification so that it can be used to rename directories. And on and on and on. Trying to put every possible combination of feature into every utility leads to unmanageable code bloat. What do all of those have in common? They are all specific features that are easily available by using the features of the operating system. That is the entire point of a Unix-like operating system. It already has all of the tools needed. You tell it what you want it to do using those features. That is the way the operating system is designed. Utilities such as dirname are simply small pieces in the complete solution. In this instance the first thing I thought of when I read your dirname -f request was a loop. while read dir; do dirname $dir; done < list Pádraig suggested xargs which was even shorter. xargs dirname < filename Both of those directly do exactly what you had asked to do. The technique works not only with dirname but with every other command on the system too. A technique that works with everything is much better than something that only works in one small place. Want to get the basename instead? while read dir; do basename $dir; done < list Want to modify the result to add a suffix? while read dir; do echo $dir.myaddedsuffix; done < list Want to modify the name in some custom way? while read dir; do echo $dir | sed 's/foo/bar/; done < list Want a sorted unique list modified in some custom way? while read dir; do echo $dir | sed 's/foo/bar/'; done < list | sort -u The possibilities are endless and as they say limited only by your imagination. Anything you can think of doing you can tell the system to do it for you. Truly a marvelous thing to be so empowered. Note that in order to be completely general and work with arbitrary names that have embedded newlines then proper quoting is required and the wisdom of today says always use null terminated strings. But if you are using a file of names then I assume you are operating on a restricted and sane set of characters so this won't matter to you. I do that all of the time. Bob From debbugs-submit-bounces@debbugs.gnu.org Thu Dec 10 12:46:28 2015 Received: (at 22128) by debbugs.gnu.org; 10 Dec 2015 17:46:28 +0000 Received: from localhost ([127.0.0.1]:39376 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1a75IR-00041e-Ts for submit@debbugs.gnu.org; Thu, 10 Dec 2015 12:46:28 -0500 Received: from usa7109mr004.acs-inc.com ([13.28.230.15]:11458) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1a75IR-0003zY-2a for 22128@debbugs.gnu.org; Thu, 10 Dec 2015 12:46:27 -0500 Received: from usa7109ht003.na.xerox.net ([13.41.230.29]) by USA7109MR004.ACS-INC.COM with ESMTP/TLS/AES128-SHA; 10 Dec 2015 11:46:25 -0600 Received: from USA7109MB022.na.xerox.net ([169.254.6.149]) by USA7109HT003.na.xerox.net ([13.41.230.29]) with mapi id 14.03.0224.002; Thu, 10 Dec 2015 11:46:25 -0600 From: "Nellis, Kenneth" To: Bob Proulx Subject: RE: bug#22128: dirname enhancement Thread-Topic: bug#22128: dirname enhancement Thread-Index: AdEypohWxQeTL2lqQz6bwSyckoTMCwAeD1mAAB8HXQAADIH7oP//rngAgABjZyA= Date: Thu, 10 Dec 2015 17:46:25 +0000 Message-ID: <0D835E9B9CD07F40A48423F80D3B5A702E9D2B20@USA7109MB022.na.xerox.net> References: <0D835E9B9CD07F40A48423F80D3B5A702E9D277D@USA7109MB022.na.xerox.net> <5668D947.8080801@draigBrady.com> <20151210092752873175265@bob.proulx.com> <0D835E9B9CD07F40A48423F80D3B5A702E9D2AC7@USA7109MB022.na.xerox.net> <20151210101835772207404@bob.proulx.com> In-Reply-To: <20151210101835772207404@bob.proulx.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [13.41.230.95] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 22128 Cc: "22128@debbugs.gnu.org" <22128@debbugs.gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) I got it. You don't like the idea. That's fine. Please close the ticket. --Ken > -----Original Message----- > From: Bob Proulx [mailto:bob@proulx.com] > Sent: Thursday, December 10, 2015 12:41 PM > To: Nellis, Kenneth > Cc: 22128@debbugs.gnu.org > Subject: Re: bug#22128: dirname enhancement >=20 > Nellis, Kenneth wrote: > > Still, my -f suggestion would be easier to type, > > but I welcome your alternatives. >=20 > Here is the problem. You would like dirname to read a list from a > file. Someone else will want it to read a file list of files listing > files. Another will want to skip one header line. Another will want > to skip multiple header lines. Another will want the exact same > feature in basename too. Another will want file name modification so > that it can be used to rename directories. And on and on and on. > Trying to put every possible combination of feature into every utility > leads to unmanageable code bloat. >=20 > What do all of those have in common? They are all specific features > that are easily available by using the features of the operating > system. That is the entire point of a Unix-like operating system. It > already has all of the tools needed. You tell it what you want it to > do using those features. That is the way the operating system is > designed. Utilities such as dirname are simply small pieces in the > complete solution. >=20 > In this instance the first thing I thought of when I read your dirname > -f request was a loop. >=20 > while read dir; do dirname $dir; done < list >=20 > P=E1draig suggested xargs which was even shorter. >=20 > xargs dirname < filename >=20 > Both of those directly do exactly what you had asked to do. The > technique works not only with dirname but with every other command on > the system too. A technique that works with everything is much better > than something that only works in one small place. >=20 > Want to get the basename instead? >=20 > while read dir; do basename $dir; done < list >=20 > Want to modify the result to add a suffix? >=20 > while read dir; do echo $dir.myaddedsuffix; done < list >=20 > Want to modify the name in some custom way? >=20 > while read dir; do echo $dir | sed 's/foo/bar/; done < list >=20 > Want a sorted unique list modified in some custom way? >=20 > while read dir; do echo $dir | sed 's/foo/bar/'; done < list | sort -u >=20 > The possibilities are endless and as they say limited only by your > imagination. Anything you can think of doing you can tell the system > to do it for you. Truly a marvelous thing to be so empowered. >=20 > Note that in order to be completely general and work with arbitrary > names that have embedded newlines then proper quoting is required and > the wisdom of today says always use null terminated strings. But if > you are using a file of names then I assume you are operating on a > restricted and sane set of characters so this won't matter to you. > I do that all of the time. >=20 > Bob From debbugs-submit-bounces@debbugs.gnu.org Fri Dec 11 12:27:24 2015 Received: (at submit) by debbugs.gnu.org; 11 Dec 2015 17:27:24 +0000 Received: from localhost ([127.0.0.1]:40672 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1a7RTX-0007cc-K7 for submit@debbugs.gnu.org; Fri, 11 Dec 2015 12:27:23 -0500 Received: from eggs.gnu.org ([208.118.235.92]:39996) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1a7RTW-0007cD-1f for submit@debbugs.gnu.org; Fri, 11 Dec 2015 12:27:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a7P1Y-0001LZ-RW for submit@debbugs.gnu.org; Fri, 11 Dec 2015 09:50:23 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: ** X-Spam-Status: No, score=3.0 required=5.0 tests=BAYES_50,FREEMAIL_FROM, FSL_HELO_BARE_IP_2,RCVD_NUMERIC_HELO autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:38402) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a7P1Y-0001LU-Oo for submit@debbugs.gnu.org; Fri, 11 Dec 2015 09:50:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33334) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a7P1S-0007CR-PS for bug-coreutils@gnu.org; Fri, 11 Dec 2015 09:50:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a7P1P-0001KQ-IK for bug-coreutils@gnu.org; Fri, 11 Dec 2015 09:50:14 -0500 Received: from plane.gmane.org ([80.91.229.3]:59592) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a7P1P-0001KH-Bg for bug-coreutils@gnu.org; Fri, 11 Dec 2015 09:50:11 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1a7P1N-0003LZ-ED for bug-coreutils@gnu.org; Fri, 11 Dec 2015 15:50:09 +0100 Received: from 90.200.237.28 ([90.200.237.28]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 11 Dec 2015 15:50:09 +0100 Received: from stephane.chazelas by 90.200.237.28 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 11 Dec 2015 15:50:09 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: bug-coreutils@gnu.org From: Stephane Chazelas Subject: Re: bug#22128: dirname enhancement Date: Fri, 11 Dec 2015 14:46:38 +0000 Lines: 116 Message-ID: <20151211144638.GA7891@chaz.gmail.com> References: <0D835E9B9CD07F40A48423F80D3B5A702E9D277D@USA7109MB022.na.xerox.net> <5668D947.8080801@draigBrady.com> <20151210092752873175265@bob.proulx.com> <0D835E9B9CD07F40A48423F80D3B5A702E9D2AC7@USA7109MB022.na.xerox.net> <20151210101835772207404@bob.proulx.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 90.200.237.28 Content-Disposition: inline In-Reply-To: <20151210101835772207404@bob.proulx.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -2.2 (--) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.2 (---) 2015-12-10 10:40:30 -0700, Bob Proulx: [...] > In this instance the first thing I thought of when I read your dirname > -f request was a loop. > > while read dir; do dirname $dir; done < list "read dir" expects the input in a very specific format and depends on the current value of IFS (like a dir called "my\dir " has to be input as "my\\dir\ " with the default value of IFS) and can't accept dir names with newline characters. Invoking the split+glob operator on $dir doesn't make sense here unless you mean the input to be treated as a $IFS delimited list of patterns. If the intention was to treat the input as a list of file paths, one per line (so can't do file paths with newline characters), then that would rather be: while IFS= read -r dir; do dirname -- "$dir"; done < list > > Pádraig suggested xargs which was even shorter. > > xargs dirname < filename That expects yet another input format. That time, it can cope with any file path, since newline can be specified using quotes like: "my dir with newline" The output of dirname however won't be post-processable. > Both of those directly do exactly what you had asked to do. The > technique works not only with dirname but with every other command on > the system too. A technique that works with everything is much better > than something that only works in one small place. The while loop you can't reasonably do for large file lists as running one dirname invocation per file is going to be prohibitive in terms of performance. The xargs approach, you can do only with GNU dirname as it supports passing more than one string as an extension over the standard. I think here we're seeing the limits of shell scripting. OK, dirname is the tool to get a dirname, but doing it in a loop is not practical/efficient and produces an ambiguous output (not to mention that file names are not necessarily valid text so the passing of that data through text utilities can be a problem) Extending all the utilities so that they can take a list of arguments from stdin instead of arguments is one solution (and one solution applied by several GNU utilities already (like --files0-from in du/sort/wc) but I agree xargs -r0 is a more generic solution and good enough for things like dirname since the number of invocations is minimised.. The --files0-from option of du/sort/wc are justified because xargs -r0 wouldn't work (as several invocations of the utilities could end-up being made which wouldn't work for them), but not for dirname. (I'd argue ls would need one for its sorting though (and an option to outut NUL delimited). That can't be applied for commands that take only one argument like basename though. GNU xargs addresses the problem of the stdin of the command being redirected (like for rm -i) with its --arg-file option The problem with dirname is that OK, GNU dirname can take several paths as arguments but then its output is not post-processable reliably ("dirname a/b a/c" and "dirname $'a\na/b'" produce the same output for instance). Here using another programming language/paradigm that has the "dirname" capability and can deal with list of strings reliably within the same command (like perl or zsh) would be a more reliable and efficient approach. zsh: files=(${(z)) id 1a7SaF-0001WV-ML for submit@debbugs.gnu.org; Fri, 11 Dec 2015 13:38:23 -0500 Received: from mail2.vodafone.ie ([213.233.128.44]:8437) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1a7SaE-0001WH-B0 for 22128@debbugs.gnu.org; Fri, 11 Dec 2015 13:38:22 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjEFACkXa1ZtTE/0/2dsb2JhbABegmlRwGCGDwKBMEwBAQEBAQGBC4Q1AQEEEiABVgsNCwkWDwkDAgECAUUGAQwIAQEeiBGiTpAYjAEBLIVahXmEH4UhAQSWco8fh2EMj1WDc2OEBD6GGQEBAQ Received: from unknown (HELO localhost.localdomain) ([109.76.79.244]) by mail2.vodafone.ie with ESMTP; 11 Dec 2015 18:38:15 +0000 Subject: Re: bug#22128: dirname enhancement To: Stephane Chazelas , 22128@debbugs.gnu.org References: <0D835E9B9CD07F40A48423F80D3B5A702E9D277D@USA7109MB022.na.xerox.net> <5668D947.8080801@draigBrady.com> <20151210092752873175265@bob.proulx.com> <0D835E9B9CD07F40A48423F80D3B5A702E9D2AC7@USA7109MB022.na.xerox.net> <20151210101835772207404@bob.proulx.com> <20151211144638.GA7891@chaz.gmail.com> From: =?UTF-8?Q?P=c3=a1draig_Brady?= X-Enigmail-Draft-Status: N1110 Message-ID: <566B1817.8070906@draigBrady.com> Date: Fri, 11 Dec 2015 18:38:15 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <20151211144638.GA7891@chaz.gmail.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 22128 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) On 11/12/15 14:46, Stephane Chazelas wrote: > 2015-12-10 10:40:30 -0700, Bob Proulx: > [...] >> In this instance the first thing I thought of when I read your dirname >> -f request was a loop. >> >> while read dir; do dirname $dir; done < list > > "read dir" expects the input in a very specific format and > depends on the current value of IFS (like a dir called "my\dir " > has to be input as "my\\dir\ " with the default value of IFS) > and can't accept dir names with newline characters. > > Invoking the split+glob operator on $dir doesn't make sense here > unless you mean the input to be treated as a $IFS delimited list > of patterns. > > If the intention was to treat the input as a list of file > paths, one per line (so can't do file paths with newline > characters), then that would rather be: > > while IFS= read -r dir; do dirname -- "$dir"; done < list > >> >> Pádraig suggested xargs which was even shorter. >> >> xargs dirname < filename > > That expects yet another input format. That time, it can cope > with any file path, since newline can be specified using quotes > like: > > "my dir > with newline" > > The output of dirname however won't be post-processable. Both GNU basename and dirname since 8.16 (2012) got the -z option to make the _output_ post-processable, along with support for processing multiple inputs. xargs splits arguments on the _input_ appropriately. In general xargs is fine for this when the tool doesn't need to process all inputs at once (like sorting or generating a total for example). cheers, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Fri Dec 11 17:08:25 2015 Received: (at 22128) by debbugs.gnu.org; 11 Dec 2015 22:08:25 +0000 Received: from localhost ([127.0.0.1]:35156 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1a7VrV-0006i9-MJ for submit@debbugs.gnu.org; Fri, 11 Dec 2015 17:08:25 -0500 Received: from mail-wm0-f54.google.com ([74.125.82.54]:36476) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1a7VrT-0006hv-Pp for 22128@debbugs.gnu.org; Fri, 11 Dec 2015 17:08:24 -0500 Received: by mail-wm0-f54.google.com with SMTP id n186so48917862wmn.1 for <22128@debbugs.gnu.org>; Fri, 11 Dec 2015 14:08:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=HnnTOaJTcLHFpl/Ve3teTtSEa4ATjo4ueSHysrJWtWk=; b=bYcfTzDADzJeDKqAjytzVYkszxaDrQac4k7PZ2pkoHfAujpPJ0622NzKtKyniiD/SE aXrFHJdL47bqkRCo4XI1LhkNss0xJqxhe35ksG8Hk1OXyx9z1XgPQqaXfcXcn91w1tjH lWxj6rRMSvdyb7pmV3g0VTqdfcbv0KZh93vdKWkiMK00kr0mxX91RdFUQgE3F5lJNoY+ PM8erQTfmJeZxwB72xDdJ7O9ynf7RD4NN7PHDkO652cmIVFiWpp7S+mDIdBfbIJVXP1M VwBdO2zBnWin+Q6TBm1do3qBiNr4mSOajGiceBrIa4064Tnra0zPXPazAGKWSpQO+7Ve B0Ig== X-Received: by 10.28.223.212 with SMTP id w203mr9185481wmg.88.1449871698148; Fri, 11 Dec 2015 14:08:18 -0800 (PST) Received: from chaz.gmail.com ([90.200.237.28]) by smtp.gmail.com with ESMTPSA id az6sm18647371wjc.25.2015.12.11.14.08.16 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 11 Dec 2015 14:08:16 -0800 (PST) Date: Fri, 11 Dec 2015 22:08:15 +0000 From: Stephane Chazelas To: =?iso-8859-1?Q?P=E1draig?= Brady Subject: Re: bug#22128: dirname enhancement Message-ID: <20151211220815.GB7891@chaz.gmail.com> References: <0D835E9B9CD07F40A48423F80D3B5A702E9D277D@USA7109MB022.na.xerox.net> <5668D947.8080801@draigBrady.com> <20151210092752873175265@bob.proulx.com> <0D835E9B9CD07F40A48423F80D3B5A702E9D2AC7@USA7109MB022.na.xerox.net> <20151210101835772207404@bob.proulx.com> <20151211144638.GA7891@chaz.gmail.com> <566B1817.8070906@draigBrady.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <566B1817.8070906@draigBrady.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 22128 Cc: 22128@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) 2015-12-11 18:38:15 +0000, Pádraig Brady: [...] > Both GNU basename and dirname since 8.16 (2012) got > the -z option to make the _output_ post-processable, > along with support for processing multiple inputs. [...] Indeed. And I can see GNU basename takes a -a option to accept more than one file path (and take the suffix to strip with -s which is how basename should have been designed in the first place) so one can do: < list xargs -r0 basename -az -- Or < list xargs -r0 basename -azs .txt -- and have a minimum number of invocations of basename and a post-processable output. All good. Thanks. -- Stephane From debbugs-submit-bounces@debbugs.gnu.org Wed Oct 24 17:35:45 2018 Received: (at control) by debbugs.gnu.org; 24 Oct 2018 21:35:45 +0000 Received: from localhost ([127.0.0.1]:40807 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gFQob-0000cA-IW for submit@debbugs.gnu.org; Wed, 24 Oct 2018 17:35:45 -0400 Received: from mail-pl1-f181.google.com ([209.85.214.181]:33581) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gFQoZ-0000bx-QK for control@debbugs.gnu.org; Wed, 24 Oct 2018 17:35:44 -0400 Received: by mail-pl1-f181.google.com with SMTP id x6-v6so2854423pln.0 for ; Wed, 24 Oct 2018 14:35:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:message-id:date:user-agent:mime-version:content-language :content-transfer-encoding; bh=lr2Q5WnL+ac2SA3qtSR6ABMz9Hqo8xmZEkPmtx94mR4=; b=RjTgpu1ll/ACJktpg/l66rdNES6exwcva4u19aWkGkEf35aan2qmFHyq7/pNhxH8bv cwbxeQXTWwgXHppUGInIJI6D4HH/Zx9c3SAGzmwwPM1gC/x4fCbUz5oYzDIuJ9QUyK9K jv9CXtoOG+OwGI4HCFWbuiorB1DdithMT8A/SNSsdIaQQvwU38gX0wNdUHxlVDIo6bjl svmTFVjA7+q1vL384coV8mFNYSGbL5keOEConwUiQeOqAyq5an6g+0sbBmtx70p/pi7O pIveIj2SyAUIKjU+q4ouJd1M0eF1iGx0GDgqvl9F4ajjQWjKP6Yq07OWex2decaOD8Cg GJlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=lr2Q5WnL+ac2SA3qtSR6ABMz9Hqo8xmZEkPmtx94mR4=; b=Q8+ytncTaN859LkB/RlYeOifBQNSwnD8BQg5xfwQ0DfInBFGl2gZZKBUEqLnOGH3U+ i2mt/vsbgKnuTJeT/xGrigz/Tel6zB3BX+EFfAXiUbVlIpm7GI6ZvmBr0m1U8FC8HzVg VchHUPxjDsPfKj+nKFL26u1XNyDZ5+Tn7lAHomjCztnPD9g3OpyKZ0Wgc31x5uO4rKXS X3XP1his9PQABzwymMT8B9U6ZwlCaS6YECsaBiZv2J0PgXsdPURCq2CkVMYlHAOcvnvQ 2x0hbRLFJZJwLg/dUaX8hf0L73qYIxuPdADBmAGwF9V0L4W+0PB4KNOviU+UCbNdqRDq 6N1w== X-Gm-Message-State: AGRZ1gKvFJFnhlssh2osq7NYSb/K2RPjDGB6SJdX007/HfAElfUY4F8f 4NaTsl7vc6JGzco+Ztw39IXsb+M2O2o= X-Google-Smtp-Source: AJdET5eogWJX4qbIxzN5IX47uOnQzQy/MQh+vY3FX3XjYjghoyNjpbwv/ayFEwKFwUfhBd7IMZrDfw== X-Received: by 2002:a17:902:a618:: with SMTP id u24-v6mr3985511plq.77.1540416937366; Wed, 24 Oct 2018 14:35:37 -0700 (PDT) Received: from tomato.housegordon.com (moose.housegordon.com. [184.68.105.38]) by smtp.googlemail.com with ESMTPSA id b19-v6sm6314680pfo.50.2018.10.24.14.35.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Oct 2018 14:35:35 -0700 (PDT) To: control@debbugs.gnu.org From: Assaf Gordon Message-ID: <5ccb278d-5d56-ec7b-4c81-eca5937aeb3f@gmail.com> Date: Wed, 24 Oct 2018 15:35:34 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: 2.0 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: severity 22128 wishlist tags 22128 wontfix retitle 22128 dirname: accept file list input close 22128 [...] Content analysis details: (2.0 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.214.181 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (assafgordon[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.214.181 listed in wl.mailspike.net] 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders 1.8 MISSING_SUBJECT Missing Subject: header 0.2 NO_SUBJECT Extra score for no subject X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) severity 22128 wishlist tags 22128 wontfix retitle 22128 dirname: accept file list input close 22128 From unknown Mon Jun 23 07:49:20 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 22 Nov 2018 12:24:06 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator