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

Re: string match simplification?



On Tue, Sep 3, 2024 at 6:57 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
This seems ok:  (and never mind deciding on how long the extension can be):

#!/usr/bin/zsh

filename=$1
extension=${filename:e}
# just in case there's a trailing dot: don't remove in unless there is an extension.
[ "$extension" ] && filename="${filename%.*}"
echo filename is: $filename
echo extension is: .$extension # I'll keep the dot on the extension.

If the input is "foo.", this script will print "filename is: foo." (note the trailing dot). Probably not what you want. If you use :r instead, you'll get the expected "foo" without the trailing dot.

Roman



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