0

I want to use bash commands in nested loops in makefile, my current code is not working. Can some one guide me what can be the problem. I have written a simple code in test target. Here, I want to go to a directory DIR_S/case1 and copy rtt.csv file into another directory DIR_D/rtt/ directory.

test: 
    cn=1; while [[ $$cn -le 2 ]] ; do \
        echo $$cn ; \
        ((cd $(DIR_S)/case\ $$cn)) ;  \
        ((cp rtt.csv $(DIR_D)/rtt/)) ; \
        ((cn = cn + 1)) ; \
    done

There is no error when I run this but i see this message and the line is not executed

/bin/sh: ((: cd /Users/Umar/Desktop/dummy1/case 1: division by 0 (error token is "/Umar/Desktop/dummy1/case 1")

One thing I noticed was that if type

cd /Users/Umar/Desktop/dummy1/case 1

at command line it will not work because of space, I also updated the above line of

((cd $(DIR_S)/case\ $$cn)) ;  \ 

to

((cd $(DIR_S)/case\\ $$cn)) ;  \

but still this line is not executed. Can someone guide me how to use bash commands in nested loops in Makefile. (I have mentioned nested loops as I intend to add another loop after this loop)

1 Answer 1

0

The Issue seemed to be resolved when I use bash commands without (( and )).

1
  • The use of (( is for arithmetic whilst ( is for subshell. The use of single `(' is nice if you want to change directory and return unconditionally to the right place at the end of subshell. Remember that arithmetic done in subshell is lost when subshell returns...
    – levif
    Sep 20, 2015 at 19:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .