> On Sun, 15 May 2016 21:35:41 +0200 > rindeal <dev.rind...@gmail.com> wrote: > >> > Dnia 15 maja 2016 15:31:29 CEST, Jan Chren <dev.rind...@gmail.com> >> > napisał(a): >> >>+ local f="${!i}" >> >>+ if [ "${f#-${findflag#-}}" != "${f}" ] ; then >> > >> > I know the original code sucked as well but could you replace this with >> > more readable [[ ${f} == -${findflag#-}* ]] or alike (note: not tested). >> >> This is just as buggy as my original implementation, I've reworked it >> and thanks to the tests I hope it's now correct. > > It is still unreadable. The point is, we use bash here, so please use > bash features (i.e. == with wildcards) to do comparison rather than > limited shell-style stripping of variables.
The thing is that "== with wildcards" cannot be used, because a) it's too greedy and b) the wildcards in ${pattern} won't expand. > >> >>+ printf "%s\n" "${f#-${findflag}=}" >> > >> > It may be a good idea to add a short explanation why you can't use echo >> > here, as a comment. >> >> I've just copied what was there before, `echo` in bash is notoriously >> wild, but with this simple string I guess it's ok, so done. > > I meant you should add a comment that you can't use echo because flags > like '-n' or '-e' would confuse it :-P. Ok, I've fixed it and added tests for such edge cases.