[patch] testsuite/testing.sh: removes obvious bashisms
Cristian Ionescu-Idbohrn
cristian.ionescu-idbohrn at axis.com
Fri May 2 07:26:46 PDT 2008
On Fri, 2 May 2008, Denys Vlasenko wrote:
> On Friday 02 May 2008 15:36, Cristian Ionescu-Idbohrn wrote:
> > On Fri, 2 May 2008, Denys Vlasenko wrote:
> >
> > > On Friday 02 May 2008 13:52, Cristian Ionescu-Idbohrn wrote:
> > > >
> > > > Obviously you don't like printf :)
> > >
> > > I don't have any problems with it. I just know that new-style
> > > scripts can break if we switch to it, because their strings can
> > > contain "%".
> > >
> > > Therefore it cannot be used.
> >
> > Do we have control over those strings?
> > Could you give an RL example?
>
> testsuite/pidof.tests
Thanks. I was afraid but I didn't know why :) What about:
-#testing "pidof -o %PPID" "pidof -o %PPID pidof.tests | grep -o -w $$" "" "" ""
-testing "pidof -o %PPID NOP" "pidof -o %PPID -s init" "1\n" "" ""
+#testing "pidof -o \045PPID" "pidof -o \045PPID pidof.tests | grep -o -w $$" "" "" ""
+testing "pidof -o \045PPID NOP" "pidof -o \045PPID -s init" "1\n" "" ""
Is it too quirky (there's already one escaped sequence in there)?
> testsuite/uuencode.tests
Same here:
-"begin 644 bb_uuenc_test.out\nM5&AE(&9A<W0 at 9W)E>2!F;W@@:G5M<&5D(&]V97(@=&AE(&QA>GD at 8G)O=VX@\n%9&]G+ at H\`\n\`\nend\n" \
+"begin 644 bb_uuenc_test.out\nM5&AE(&9A<W0 at 9W)E>2!F;W@@:G5M<&5D(&]V97(@=&AE(&QA>GD at 8G)O=VX@\n\0459&]G+ at H\`\n\`\nend\n" \
Wouldn't that work with printf?
There is also the problem when a real '\' is part of the string, and would
need to be replaced by either '\\' or '\134'. And more :( What about
some stray '$' in the wrong neighbourhood:
---8<---
#!/bin/dash -e
foo=FOO
bar=date
echo "echo: var: expect a FOO here '$foo'"
printf "printf: var: expect another FOO here '$foo'\n"
echo "echo: expr: today's '$($bar)' weather"
printf "printf: expr: today's '$($bar)' weather\n"
exit 0
---8<---
You need to watch for that too.
Nirvana is still far away :)
Anyway, as long as you have control over the input yo can get around.
It's harder if you don't.
Cheers,
--
Cristian
More information about the busybox
mailing list