5 ms·
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.
by dvh 11y ago
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.
- dhamidi 11y agoWhy 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.
- protomyth 11y ago> 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]
- philjackson 11y agoWhy do you expect basename to do something with stdin?
- ksherlock 11y agoif you need to pipe it in, you should basename `echo $PWD`
- protomyth 11y agouhm, 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.
- wyldfire 11y agoHow about this? for f in $(cat a.txt); do basename "$f"; done
- yrro 11y ago1. Broken by filenames that contain whitespace. 2. The shell will expand * and ? (maybe others) in the filenames
- erdbeerkaese 11y agoAnother way: while read line ; do basename "$line" ; done < a.txt
- pixelbeat 11y agoxargs basename -a < a.txt
- protomyth 11y agoI take it -a is one of those GNU extensions?
- protomyth 11y agoI 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.
- pixelbeat 11y agoDiscussed at http://lists.gnu.org/archive/html/coreutils/2011-01/msg00080.html 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
- feld 11y ago$ echo ${PWD##*/} etc use your shell to its full power
- yrro 11y agoA practical issue: how many paths should basename accept on stdin? If more than 1, how should they be delimited?
- andrewchambers 11y agoobviously with a newline like every other unix tool. sort, uniq, grep etc.
- yrro 11y agoBut paths can contain newlines.
- scrollaway 11y agoMost tools that deal with paths delimit them on newlines and support a -z or -0 flag to delimit with \0.