3 ms·
1. Thanks for this, instantly added to my dotfiles 2. You nerd-sniped me into getting rid of the unnecessary `cut` process :) file=${result%%:*} line=${re
by ForkMeOnTinder 3y ago
1. Thanks for this, instantly added to my dotfiles
2. You nerd-sniped me into getting rid of the unnecessary `cut` process :)
file=${result%%:*}
line=${result#*:}
line=${line%%:*}
- imakira 3y agoThanks! I have tried using bash substitution to solve it but failed (I just learned the difference between "#" and "##").
- js2 3y agoFYI, these substitutions are POSIX: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02 https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V... Also a couple mnemonic hints: % vs #. On US keyboards, # is shift-3 and is to the left of % which is shift-5. So # matches on the start (left) and % matches on the end (right). # vs ## (or % vs %%). Doubling the character makes the match greedy. It's twice a wide so it needs to eat more. Bash also supports ${parameter/pattern/string} and ${parameter//pattern/string} (and a bunch others besides) which are not POSIX: https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html https://www.gnu.org/software/bash/manual/html_node/Shell-Par...
- imakira 3y agoThanks for the great information!
- kaba0 3y agoJesus, bash really is an abomination