[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Using 'echo' in a makefile/what shell is used?



Kris Huber wrote:
> But on my debian system that help message doesn't print correctly
> due to '\t' not expanding to tab and '\n' not expanding to cause new
> lines.  I finally figured out that I can use 'echo -e' to print the
> help text correction from within gmake.

You have run into one of the most annoying things about bash being
installed as /bin/sh on a system.  It is almost POSIX compliant.  But
in this regard is falls down.  POSIX requires echo to interpret quoted
characters like SysV does.  But bash follows BSD and requires -e.  The
result of this conflict is that portable scripts can't use this
feature at all and must avoid it.  It is a shame.  Sigh.

> I'd like to make this the default behavior on my system so the
> Makefile remains unchanged, however.

About the only thing you can do is install a better /bin/sh
replacement.  'ash' is probably the best choice in this regard.  Then
replace the /bin/sh symlink to bash with a symlink to ash.

  apt-get install ash
  ln -sfn /bin/ash /bin/sh

The 'ash' shell is much more standard and the echo there will work as
you expect it to work.

> I can use the 'shopt -s xpg_echo' command in my .bashrc file to make
> bash have this behavior, but yet this doesn't have effect apparently
> for the commands given by gmake.

Correct.  Your .bashrc is only for interactive shells.  (Okay, remote
shells too.  But I am simplifying.)  It should not run for batch
scripts.

> Does gmake do it's own emulation of a command shell similar to
> /bin/sh or /bin/bash?

Nope.

> Can I make the default echo command from within gmake always behave
> as though it had the '-e' option?

File a bug against bash to convert to POSIX on this point.  It is not
a make problem.

Your best option is to avoid echo when using any escape sequences at
all.  It is a can of worms.  Instead use 'printf' which is a new
command with no legacy that is required to support the standard
features on all systems.

  printf "\tfoo: bar\n"

[A side note.  You keep calling it 'gmake'.  Why?  Is there another
option for 'make' on GNU systems?  Why not just call it 'make'?]

Bob

Attachment: pgpTqZzsKT0YZ.pgp
Description: PGP signature


Reply to: