Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8288329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:15:44+00:00 2026-06-08T12:15:44+00:00

I am trying to have my Makefile echo text without the trailing new line,

  • 0

I am trying to have my Makefile echo text without the trailing new line, but am unable to. I am experiencing the behavior on OS X (on Linux everything works as expected).

Makefile

a:
    @echo -n "hello"

b:
    @echo -n hello

c:
    @/bin/echo -n "hello"

Output:

$make a
-n hello
$make b
hello$make c
hello$

In other words, the make a is broken. What exactly is happening? Is make using a built-in echo? Clearly the presence of the double quotes changes the behavior, but why?

Update

As discovered by @chepner, using the full path to /bin/echo in the makefile understands the -n flag correctly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:15:45+00:00Added an answer on June 8, 2026 at 12:15 pm

    Something about the quotes confuses make. Your code behaves the same for me, but the following works as expected:

    help:
            @echo -n Shouldn\'t print a newline
    

    Hardcoding the path to the executable also works:

    help:
            @/bin/echo -n "Shouldn't print a newline"
    

    The Mac OS X man page for echo, while discussing the existence of shell built-in echos, mentions that the echo of sh(1) does not support the -n option, but that fails to explain (to me, anyway) why my first alternative works.


    Confirmation that make is using sh to execute the commands by default. Make manual 5.3.2 Choosing the Shell specifies this hehavrior:

    The program used as the shell is taken from the variable SHELL. If
    this variable is not set in your makefile, the program /bin/sh is used
    as the shell. The argument(s) passed to the shell are taken from the
    variable .SHELLFLAGS. The default value of .SHELLFLAGS is -c normally,
    or -ec in POSIX-conforming mode.

    In

    SHELL = bash
    help:
            @echo -n "Shouldn't print a newline"
            @echo -n Shouldn\'t print a newline
    

    both echo statements behave the same (no newlines printed). So without that variable, we have bash pretending to be sh, but evaluating the two lines differently. Question 1: why? Question 2: is the second line the native bash echo or /bin/echo, rather than the emulated sh echo?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to solve an issue with makefile. I have a main.cpp and then
I have a makefile with the following code. I'm trying to set a variable
Hello I have a problem while trying to run a makefile. I change the
I am trying to write a Makefile for a JVM port. I have already
I am new to g++ and Makefile. I am trying to link this BeBOP
I am new to g++ and Makefile. I am trying to link this BeBOP
EDITED I'm trying to have source files recompiled without having to specify header files
I’m trying to learn makefiles. I have the following Makefile: ctx/%.ctx: rst/%.rst texlua rst_parser.lua
I've been trying for over an hour to fix my makefile but I break
I already have a mysql server setup via MAMP. But when trying to install

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.