[Top][All Lists]

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

Re: Bash - various feature requests

From: Richard Neill
Subject: Re: Bash - various feature requests
Date: Fri, 29 Dec 2006 22:42:02 +0000
User-agent: Thunderbird (X11/20061115)

Dear Grzegorz,

Thanks for your helpful reply.

Grzegorz Adam Hankiewicz wrote:
On 2006-12-27, Richard Neill <address@hidden> wrote:
1)substr support for a negative length argument.
For example,
  echo ${stringZ:2:-1}  #prints cde

i.e. ${string:x:y}
  returns the string, from start position x for y characters.
  but, if x is negative, start from the right hand side
  and if y is negative, print up to the end, -y.

This would work the same way as PHP, and be extremely useful for, say,
removing an extension from a filename.

If extension removal is all you need, you can already do it.

        $ for f in *; do echo $f; done
        $ for f in *; do echo ${f%.*}; done

I did know about this, but it seems slightly like a sledgehammer on a nut, using a regexp instead of a substring. Also, this way doesn't allow you to trim both the start and the end. Lastly, I just think it would be a really useful (and easy-to-implement, I think) feature, which is consistent with the use of PHP and perl. At the moment, the first parameter may be any integer (postive or negative), but the second parameter can only be positive.

Best wishes,


reply via email to

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