News for hackers. Stuff that matters.
Re:GNU Coreutils Gotchas by dvh on Monday November 30, 2015 @08:19AM (#10649196)
for me, it's details like this:

  $ basename $PWD
  etc
  $ echo $PWD | basename
  <this prints nothing>
I even reported it decade ago but nobody cares.
Re:GNU Coreutils Gotchas by pixelbeat on Monday November 30, 2015 @10:07AM (#10649726)
Discussed at http://lists.gnu.org/archive/html/coreutils/2011-01/msg00080...

Summary of that is you can filter using xargs like:

    get_file_paths | xargs basename -a
No point having two ways to do something, especially when there are caveats about enabling stdin processing
Re:GNU Coreutils Gotchas by dhamidi on Monday November 30, 2015 @08:42AM (#10649284)
Why should basename accepts its argument on stdin? It doesn't act as a filter, processing a stream of data, but rather as a plain function.
Re:GNU Coreutils Gotchas by protomyth on Monday November 30, 2015 @09:11AM (#10649427)
> Why should basename accepts its argument on stdin?

Because a lot of people have use for a filter version

> It doesn't act as a filter, processing a stream of data, but rather as a plain function.

That's the problem with a lot commands, some work as filters, some as simple commands, and other do both. The reasoning on the decision is confusing.

[edit: yes, combining with xargs will often work]

Re:GNU Coreutils Gotchas by philjackson on Monday November 30, 2015 @08:42AM (#10649285)
Why do you expect basename to do something with stdin?
Re:GNU Coreutils Gotchas by protomyth on Monday November 30, 2015 @09:14AM (#10649443)
I ended up writing my own version of basename and dirname that acted as both filters and commands. Its actually not that hard given the functions you have (might give it another go given the whole pledge thing just to see how it would work). URL versions of these commands are also very useful and not too hard to program in perl.
Re:GNU Coreutils Gotchas by yrro on Monday November 30, 2015 @11:25AM (#10650155)
A practical issue: how many paths should basename accept on stdin? If more than 1, how should they be delimited?
Re:GNU Coreutils Gotchas by andrewchambers on Monday November 30, 2015 @02:56PM (#10651354)
obviously with a newline like every other unix tool. sort, uniq, grep etc.
Re:GNU Coreutils Gotchas by yrro on Wednesday December 02, 2015 @06:17AM (#10662283)
But paths can contain newlines.
Re:GNU Coreutils Gotchas by scrollaway on Thursday December 03, 2015 @03:52PM (#10672544)
Most tools that deal with paths delimit them on newlines and support a -z or -0 flag to delimit with \0.
Re:GNU Coreutils Gotchas by feld on Monday November 30, 2015 @10:19AM (#10649793)

    $ echo ${PWD##*/}
    etc

use your shell to its full power
Re:GNU Coreutils Gotchas by ksherlock on Monday November 30, 2015 @09:05AM (#10649382)
if you need to pipe it in, you should

    basename `echo $PWD`
Re:GNU Coreutils Gotchas by protomyth on Monday November 30, 2015 @09:17AM (#10649458)
uhm, what?

Can you give an example where I have a file (a.txt) of 100 file names and need the basename of each? I'm pretty sure dvh just used echo to show a simple example, not an actual use.

Re:GNU Coreutils Gotchas by erdbeerkaese on Monday November 30, 2015 @09:55AM (#10649661)
Another way:

  while read line ; do basename "$line" ; done < a.txt
Re:GNU Coreutils Gotchas by wyldfire on Monday November 30, 2015 @10:08AM (#10649733)
Yeah, I think I prefer yours. Probably more robust wrt filenames-with-whitespace too.
Re:GNU Coreutils Gotchas by protomyth on Monday November 30, 2015 @11:23AM (#10650144)
Both solutions although nice and helpful pretty much illustrate why I ended up writing a filter capable version.
Re:GNU Coreutils Gotchas by wyldfire on Monday November 30, 2015 @09:52AM (#10649643)
How about this?

    for f in $(cat a.txt); do basename "$f"; done
Re:GNU Coreutils Gotchas by yrro on Monday November 30, 2015 @11:27AM (#10650174)
1. Broken by filenames that contain whitespace.

2. The shell will expand * and ? (maybe others) in the filenames

Re:GNU Coreutils Gotchas by pixelbeat on Monday November 30, 2015 @11:25AM (#10650159)

    xargs basename -a < a.txt
Re:GNU Coreutils Gotchas by protomyth on Wednesday December 02, 2015 @11:33AM (#10663907)
I take it -a is one of those GNU extensions?