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