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

Re: string match simplification?



cc:zsh-users

On Tue, 3 Sep 2024 at 18:02, Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx> wrote:
On Tue, 3 Sep 2024 at 17:53, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:

#!/usr/bin/zsh

filename=$1
extension="${filename##*.}"
(( $#filename == $#extension )) && extension=
if (( $#extension > 0 && $#extension < 6 )); then
    filename="${filename%.*}"
else
    extension=
fi                                            
echo filename is: $filename
echo extension is: $extension

Try it on "/foo.bar/baz".

You might be looking for ${filename:e}. It does not differentiate between short vs long extensions, but you probably shouldn't either.

Roman




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