Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Even to this day, years later, I have to look up bits and pieces here and again if I don't use some of the ${}-type substitutions frequently.

In that case I think you should give Elvish a chance then :)

Honestly one of the motivations for writing a shell language was that I could never remember which of ${x%y} and ${x#y} is for trimming the suffix vs prefix. So Elvish just use function syntax - "str:trim-suffix $x y" and "str:trim-prefix $x y" - which I highlighted in the explainer of the first snippet (https://elv.sh/learn/scripting-case-studies.html#jpg-to-png....).



# is to the left of $ and removes the prefix. % is to the right of $ and removes the suffix.


I, like the person you replied to, will surely remember it for good thanks to your reminder.


I mean, people learn silly things all the time; I think, often, learning the pattern behind something can make a thing much more transparent... I, too, struggled with this particular distinction until I realized that the choice of characters wasn't, in fact, arbitrary.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: