[LTP] new shell library

Cyril Hrubis chrubis@suse.cz
Mon Oct 31 11:39:06 CET 2016


Hi!
> I don't recall original ROD email thread, but did we consider eval and
> passing entire command as single argument? For most commands it would
> seem to be as simple as adding quotes around, awk though needs some
> escaping:
> 
> #!/bin/sh
> 
> ROD_BASE()
> {
>         eval $@
> }
> 
> ROD()
> {
>         ROD_BASE "$@"
>         if [ $? -ne 0 ]; then
>                 tst_brk TBROK "$@ failed"
>         fi
> }
> 
> ROD_SILENT()
> {
>         ROD_BASE "$@" > /dev/null 2>&1
>         if [ $? -ne 0 ]; then
>                 tst_brk TBROK "$@ failed"
>         fi
> }
> 
> sleep 1 &
> ROD jobs
> ROD "ps | awk '{print \$1}' > tempfile"

I wanted to avoid putting the whole command line into "" as well as the
need to escape $ signs inside of '', etc.

For instance if I wanted to print literal '\n' I would have to do:

ROD echo "\\\\n"

whereas with the C helper we can do just:

ROD echo "\\n"


I'm not saying that the C binary is the best solution to the problem but
I do not thing that using eval does not seem to be much better, it's
certainly shorter to implement though.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list