简体   繁体   中英

Using foreach loop in makefile with tcsh shell

I'm trying to run:

SHELL   =/usr/bin/tcsh
foo: 
    @foreach i ( "a" "b" "c")\
    echo $$i\
    end

But I get this error

i: Undefined variable.
make: *** [foo] Error 1

I found this question and answer , but looks like it uses bash, not tcsh.

The short answer is, you should not ever use tcsh , at least not for makefiles. My personal opinion is that it's high time csh and all derivatives were relegated to the dustbin of history, for all purposes. But they definitely are not usable in makefiles.

From that link, note for example: You can't combine multiline constructs in a csh using semicolons.

In addition to the problems they have with single-line scripts, they won't work with make's parallel jobserver support because they do nasty things with file descriptors.

SHELL = /usr/bin/tcsh
# but we can't use its loop constructs as they're multi-line

foo: 
    @sh -c 'for i in a b c; do echo $$i; done'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM