79080793

Date: 2024-10-12 10:26:58
Score: 0.5
Natty:
Report link

I know I could test "Does this string have an extension?" with an if-statement, then if it does have an extension I can use ${var:e}

You can do that without the if-statement like this:

${${var:e}:+.$var:e}

If the string resulting from the expansion of $var:e isn't empty, substitute .$var:e. This uses the ${name:+word} expansion (man zshexpn says "If name is … non-null, then substitute word; otherwise substitute nothing.") at the second layer of a nested expansion.

Reasons:
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (0.5):
Posted by: rowboat