Can't access files from within makefile

Mike

Whenever I do

for f in data/*; echo $f; done

from a terminal, it correctly outputs every path.

However, if I add the said line to a makefile, let's say

test:
    for f in data/*; echo $f; done

and then run make test, instead of outputting the files it always outputs an empty string. It does this a number of times equal to the number of files/directories in the directory so it seems to loop correctly.

Why is that?

Edit: I found that doing $$f instead of $f does the trick but malforms the output if, for example, I use time to time the command.

Edit #2: Here's an example of the time command:

from makefile: for f in data/ascending_order/*; do time echo $$f; done

data/ascending_order/01/
0.00user 0.00system 0:00.01elapsed 0%CPU (0avgtext+0avgdata 804maxresident)k
0inputs+0outputs (0major+232minor)pagefaults 0swaps

from terminal for f in data/ascending_order/*; do time echo $f; done

data/ascending_order/01

real    0m0.001s
user    0m0.000s
sys     0m0.000s
filbranden

The first issue (echo $f) is due to escaping inside the Makefile, if you use $f then make will think you're referring to the make variable instead of the shell variable and it will expand that (to empty) which will get your shell to run a single echo with a blank line for every file. The solution is to escape the $ by doubling it, in other words, use $$f, in which case make will consume one of the $s and pass the shell a $f, which is what you want.


Regarding the second issue (format of time output), what you're seeing is the difference in output format between the bash built-in time and the external command /usr/bin/time.

make will run the commands in your Makefile by passing them to /bin/sh, which some Linux distributions (most notably Debian and Ubuntu) ship pointing to dash, which is a simpler shell that doesn't implement a built-in time and would end up invoking the external command in that case.

You can get the bash time output by telling make to execute the commands in your Makefile using bash, which you can do with this variable assignment in your Makefile:

SHELL = /bin/bash

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Can't access static field via `super` from within subclass?

From Dev

Can't access variables from within the thenEvaluate() function in CasperJS

From Dev

Android: can't access view from within Thread

From Dev

Can't access state from within React.Children.map

From Dev

C++ Makefile Can't Find Files

From Dev

Can't access files on mounted shared folder from windows

From Dev

Can't access different JSP files from index with servlet

From Dev

Access data files from within a python package

From Dev

Can’t Access Files on LAN

From Dev

can't access object within UIPanGestureRecognizer

From Dev

Can't access lists within objects in Python

From Dev

Can't access variable within class instance

From Dev

Can not access ingress service from within cluster

From Dev

Can't access the Android Device from Remote machine within same lan

From Dev

Why can't I access a shared folder from within my Virtualbox machine?

From Dev

Can't access my server from within the network after changing ISPs (new router)

From Dev

Why can't I access a public string from a method within the same class C#

From Dev

Makefile working in Linux but not under Windows, can't find files in subdirectory

From Dev

Git commit from within a Makefile

From Dev

Apache can't access files in home folder

From Dev

lstat: can't access files in another directory

From Dev

Java Applet Can't Access Files

From Dev

Can't access all files in subfolder

From Dev

How to access files in iCloud Drive from within my iOS app?

From Dev

Can't access files from src/main/resources via a test-case

From Dev

Can malware from Windows access Ubuntu files?

From Dev

Can't "compile" the makefile

From Dev

Can't "compile" the makefile

From Dev

Why can't I access `this` within an arrow function?

Related Related

  1. 1

    Can't access static field via `super` from within subclass?

  2. 2

    Can't access variables from within the thenEvaluate() function in CasperJS

  3. 3

    Android: can't access view from within Thread

  4. 4

    Can't access state from within React.Children.map

  5. 5

    C++ Makefile Can't Find Files

  6. 6

    Can't access files on mounted shared folder from windows

  7. 7

    Can't access different JSP files from index with servlet

  8. 8

    Access data files from within a python package

  9. 9

    Can’t Access Files on LAN

  10. 10

    can't access object within UIPanGestureRecognizer

  11. 11

    Can't access lists within objects in Python

  12. 12

    Can't access variable within class instance

  13. 13

    Can not access ingress service from within cluster

  14. 14

    Can't access the Android Device from Remote machine within same lan

  15. 15

    Why can't I access a shared folder from within my Virtualbox machine?

  16. 16

    Can't access my server from within the network after changing ISPs (new router)

  17. 17

    Why can't I access a public string from a method within the same class C#

  18. 18

    Makefile working in Linux but not under Windows, can't find files in subdirectory

  19. 19

    Git commit from within a Makefile

  20. 20

    Apache can't access files in home folder

  21. 21

    lstat: can't access files in another directory

  22. 22

    Java Applet Can't Access Files

  23. 23

    Can't access all files in subfolder

  24. 24

    How to access files in iCloud Drive from within my iOS app?

  25. 25

    Can't access files from src/main/resources via a test-case

  26. 26

    Can malware from Windows access Ubuntu files?

  27. 27

    Can't "compile" the makefile

  28. 28

    Can't "compile" the makefile

  29. 29

    Why can't I access `this` within an arrow function?

HotTag

Archive