Option for basename to strip prefix in stead of suffix

Bug #173211 reported by Pander
2
Affects Status Importance Assigned to Milestone
coreutils (Ubuntu)
Triaged
Wishlist
Unassigned

Bug Description

Binary package hint: coreutils

The tool basename should have an option to strip prefix in stead of suffix.

Now it can only cut off characters at the end of a string, but for some operations it is desirable to cut chararcters from the beginning of the string.

Implementing this request will allow users to have more control over using derived versions of filenames.

Daniel T Chen (crimsun)
Changed in coreutils:
importance: Undecided → Wishlist
Revision history for this message
C de-Avillez (hggdh2) wrote :

Thank you for opening this bug and helping making Ubuntu better. Before I propose this upstream, I would like to know more about what you would like to have -- is it just a fixed prefix (pretty much like the suffix currently supported)?

For example (and supposing this new option is to be triggered by the '-p' or '--prefix' parameter):

basename --prefix atest /this/is/a/sample/atest-data.filename

would return '-data.filename', while

basename --prefix atest /this/is/a/sample/atest-data.filename .filename

would return '-data'.

Is this a correct interpretation?

Thanks.

Changed in coreutils:
status: New → Incomplete
Revision history for this message
Pander (pander) wrote :

current functionality of basename:

basename atest /this/is/a/sample/atest-data.filename
atest
basename atest atest-data.filename
atest
basename atest-data atest-data.filename
atest-data

suggested new functionality as you propose indeed:

basename --prefix /this/is/a/sample/atest /this/is/a/sample/atest-data.filename
-data.filename
basename --prefix atest /this/is/a/sample/atest-data.filename
-data.filename
basename --prefix atest /this/is/a/sample/atest-data.filename .filename
-data

Changed in coreutils:
status: Incomplete → Confirmed
Revision history for this message
C de-Avillez (hggdh2) wrote :

Hi Pander,

Thank you for your response. But there are some of your examples that look like they are slightly misconstrued: the syntax for 'basename' is 'basename <file name> <suffix>'. So -- although syntactically correct -- your current functionality examples leave me wit a bit of a taste of a incorrect call.

More importantly, the first example on the suggested functionality does not make much of a sense to me:

basename --prefix /this/is/a/sample/atest /this/is/a/sample/atest-data.filename
-data.filename

Here's the reason: basename strips directories from a provided file name. As such, it does not (for me) make sense to have a prefix that includes directory parts (since there will be none in the returning string). The prefix *could* be given as shown, but it would never match (very much like giving an incorrect suffix).

Can you please clarify what you would like by this first example?

Changed in coreutils:
status: Confirmed → Incomplete
Revision history for this message
Pander (pander) wrote :

I just did some tests with basename in order to be sure what it does when a complete path is supplied. This is not an extra requirement, just an extra check to cover those cases.

Changed in coreutils:
status: Incomplete → Confirmed
Revision history for this message
C de-Avillez (hggdh2) wrote :

Thanks. I will propose it upstream. Let's see how it is received.

Changed in coreutils:
status: Confirmed → Triaged
Revision history for this message
Pander (pander) wrote :

Any updates on this?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.