Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: string match simplification?




On Tue, Sep 3, 2024 at 12:36 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:


On 2024-09-03 09:03, Roman Perepelitsa wrote:
You might be looking for ${filename:e}. It does not differentiate between short vs long extensions, but you probably shouldn't either.

Now that's compact.  What's it's antimatter twin -- grab everything but the extension?

That's :r.  (It stands for "root".)

There's also :h and :t (head and tail) for pathnames: :h is the directory component, and :t the bare filename.  So if filename=/foo/bar/baz.txt you have:

$filename:h      /foo/bar

$filename:t      baz.txt

$filename:r      /foo/bar/baz

$filename:t:r    baz

$filename:e      txt


--
Mark J. Reed <markjreed@xxxxxxxxx>


Messages sorted by: Reverse Date, Date, Thread, Author