Hacker News new | ask | show | jobs
by olsgaarddk 1954 days ago
That's a really neat way of trimming the file extension, something that can end up being quite tedious to do with SED.

Do you know of a cheatsheet that describes what all the percentage sign means and other things you can do with parameter expansions?

2 comments

The bash hackers wiki has a pretty good list of the bash/posix one, tldp does too, but I find it less straight forward.

https://wiki.bash-hackers.org/syntax/pe

https://tldp.org/LDP/abs/html/parameter-substitution.html

The zsh docs are good for the zsh specific expansions, but more man page than cheatsheet, though they do have an intro doc on it that's more cheatsheet like but less complete.

http://zsh.sourceforge.net/Doc/Release/Expansion.html

http://zsh.sourceforge.net/Intro/intro_12.html

The old way to remove a file extension is using basename:

   basename -s .png example.png
   example
Also strips the path and you have to know the extension name(s). For my examples, "cut" would be appropriate. But those substitutions tend to work in anything POSIX, not just bash/zsh.