Echo

James Logan III logan at vsedev.VSE.COM
Thu Dec 1 12:16:25 AEST 1988


In article <6557 at june.cs.washington.edu> ka at june.cs.washington.edu (Kenneth Almquist) writes:
# I've been implementing a public domain shell and I'm wondering what to
# do about the echo builtin.  The System V echo command interprets a number
# of escape sequences (e.g. \n for newline) which the BSD echo does not,
# so I can...
#
# 3.  Don't provide an echo builtin, so users get whatever echo command is
#     installed in /bin.  This follows the principle of least surprise, but
#     it makes shell scripts run slowly and does nothing for portability.
# 

You should write a shell-script that is called by your makefile
to test the echo in /bin and see which version is already
installed.

When you know which one is installed, just set an environment
variable, like ECHOTYPE, to either "BSD_ECHO" or "SYSV_ECHO" and
call "make echo.o".  (Make calls the script "makemyshell4me"
which calls "make echo.o" and returns to the first make.  Get it? :-)

In the makefile, just do something like this:     

	# Uncomment ECHOTYPE and set it to BSD_ECHO or SYSV_ECHO
	# below to override the automatic configuration in the
	# "makemyshell4me" shell script.
	# ECHOTYPE =

	all: echo myshell

	echo: echo.c
		./makemyshell4me

	echo.o:
		cc $(CCFLAGS) -D $(ECHOTYPE) echo.c

	myshell: echo.o other_modules.o
		cc $(LDFLAGS) echo.o other_modules.o

This way the person who compiles your shell can either just type
"make" and let your program automatically configure itself to use
the echo like the one in that person's /bin, or he can explicitly
specify the other version in the makefile by setting "ECHOTYPE"
appropriately.   

			-Jim

-- 
Jim Logan		logan at vsedev.vse.com
(703) 892-0002		uucp:	..!uunet!vsedev!logan
			inet:	logan%vsedev.vse.com at uunet.uu.net



More information about the Comp.unix.wizards mailing list