[petsc-dev] printf versus echo -e/-n

Satish Balay balay at mcs.anl.gov
Sat Oct 20 11:28:58 CDT 2012


On Sat, 20 Oct 2012, Jed Brown wrote:

> On Sat, Oct 20, 2012 at 10:59 AM, Matthew Knepley <knepley at gmail.com> wrote:
> 
> > On Sat, Oct 20, 2012 at 11:46 AM, Jed Brown <jedbrown at mcs.anl.gov> wrote:
> >
> >>
> >> https://bitbucket.org/petsc/petsc-dev/changeset/26de1ead89b9285efb27a8689180876aa83921a5
> >>
> >>
> >> http://stackoverflow.com/questions/11530203/what-is-more-portable-echo-e-or-using-printf
> >
> >
> > Okay, I will bite. Why would you use the clearly less portable solution?
> >
> 
> I was pointing out that PETSc uses echo in many places. I think Satish's
> new use of echo -e will be an issue somewhere, so we should use printf
> there. Also, all the run targets use echo without a flag, but with \n in
> the string. This is not escaped. You'll see that I started using printf for
> such examples.
> 
> $ grep 'printf' src/**/makefile
> src/mat/examples/tests/makefile:           ${DIFF} output/ex38_1.out
> ex38_1.tmp || printf "${PWD}\nPossible problem with ex38_1, diffs above
> \n========================================="; \
> src/mat/examples/tests/makefile:           ${DIFF} output/ex38_2.out
> ex38_2.tmp || printf "${PWD}\nPossible problem with ex38_2, diffs above
> \n========================================="; \
> src/mat/examples/tests/makefile:           ${DIFF} output/ex38_2.out
> ex38_2.tmp || printf "${PWD}\nPossible problem with ex38_3, diffs above
> \n========================================="; \

>>>>>
printf is more portable. It should always be preferred over echo -e. If targeting bash/zsh/ksh 
<<<<

is printf portable with  bourne shell aswell? Because thats what we target.

I don't really need '-e' there. Instead of

>>>
mpif90 -show: ln -s /sandbox/petsc/software/mpich-1.2.7p1/include/mpif.h mpif.h
ifort -L/sandbox/petsc/software/mpich-1.2.7p1/lib -lmpichf90 -lmpich -lpthread -lrt
rm -f mpif.h
<<<
I can do with:

>>>
mpif90 -show: ln -s /sandbox/petsc/software/mpich-1.2.7p1/include/mpif.h mpif.h (newline) ifort -L/sandbox/petsc/software/mpich-1.2.7p1/lib -lmpichf90 -lmpich -lpthread -lrt (newline) rm -f mpif.h
<<<

Satish


> ...
> 




More information about the petsc-dev mailing list