coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [coreutils] basename/dirname can't handle stdin?


From: Jeff Blaine
Subject: Re: [coreutils] basename/dirname can't handle stdin?
Date: Thu, 13 Jan 2011 18:35:46 -0500
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7

Eric wrote:
basename -a -s suffix str1 str2: same (-a is only required for exactly
two arguements, and is implied for 0 or for more than 2 args)

basename -a -s .txt foo.txt bar.txt baz.txt

So you're saying -a is redundant there?  Sorry, I'm not
familiar with BSD's basename at all.  Just looking to
implement what you want.

On 1/13/2011 6:15 PM, Jeff Blaine wrote:
So then, please review. One question at the bottom.

# Most basic usage
basename /foo/bar.txt => bar.txt


# Old/current "basename NAME SUFFIX" compat-
# ibility
basename /foo/bar.txt .txt => bar


# ERROR, one too many operands
basename /foo/bar.txt /x.txt /y.txt => ERROR


# BSD-adopted flag to signify no args are a
# suffix, process all
basename -a /foo/bar.txt /x/y.txt => bar.txt
y.txt


# For completeness, showing 3 args with -a
basename -a /foo/bar.txt /x/y.txt /a/b.txt => bar.txt
y.txt
b.txt


basename -s .txt -a /foo/bar.txt /x/y.txt /a/b.txt => bar
y
b


# No args means read stdin (-f,--filter mode)
cat filelist.txt | basename => bar.txt
y.txt
b.txt


# Only "-s <arg>" means read stdin (-f,--filter
# mode)
cat filelist.txt | basename -s .txt => bar
y
b


# Handle NUL-terminated stdin
find / -print | basename --file0-from=- => bar.txt
y.txt
b.txt


# Handle NUL-terminated stdin with suffix strip
# (assuming /hh has our 3 files in it and is
# readable)
find /hh -print | basename --file0-from=- -s .txt => bar
y
b


# Handle NUL-terminated FILE input
find / -print | basename --file0-from=FILE => bar.txt
y.txt
b.txt

etc...

Is "-f,--filter" necessary?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]