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 8099911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:33:58+00:00 2026-06-05T22:33:58+00:00

I have the following gnu make script: for hdrfile in $(_PUBLIC_HEADERS) ; do \

  • 0

I have the following gnu make script:

for hdrfile in $(_PUBLIC_HEADERS) ; do \
    echo $(dir $$hdrfile) ; \
done

The _PUBLIC_HEADERS variable has a list of relative paths, like so:

./subdir/myheader1.h
./subdir/myheader2.h

The output I get from the for loop above is:

./
./

I expect to see:

./subdir/
./subdir/

What am I doing wrong? Note that if I change the code to:

echo $(dir ./subdir/myheader1.h)

it works in this case. I think maybe it has something to do with the for loop but I’m not sure.

  • 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-05T22:34:00+00:00Added an answer on June 5, 2026 at 10:34 pm

    You are confusing make variables (or functions) with shell variables when executing the for-loop. Note that $(dir ...) is a make construct that gets expanded by make before the command is executed by the shell. However, you want the shell to execute that command inside the loop.

    What you could do is replace $(dir) with the corresponding command dirname which gets executed by the shell. So it becomes:

    for hdrfile in $(_PUBLIC_HEADERS) ; do \
        dirname $$hdrfile ; \
    done
    

    This should give the desired result.

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

Sidebar

Related Questions

I'm using GNU Make 3.81, and I have the following rule in my Makefile:
Let's say we have the following mega-simple Python script: print Initializing.... a=10 print Variable
I am using GNU autotools for my project. The configure.ac script has the following
Typping make (Gnu Make) with the following Makefile (assuming files foo.x and foo.y are
I have the following in configure.ac: AC_CHECK_PROGS(MAKE,$MAKE make gmake,error) if test x$MAKE = xerror
I have the following situation: There is a windows folder that has been mounted
GNU/Make manual §5.7 states the following: 5.7 Recursive Use of make Recursive use of
The -size flag for GNU find behaves strangely. Let's say I have the following
I have following method in wcf webenabled service Public Person AddPerson(Person p); As of
I have following requirement, I have C#/.Net console application, which refers to 'System.Data.Sqlite.dll' 'System.Data.Sqlite.dll'

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.