/bin/sh: pushd: not found

前端 未结 11 658
借酒劲吻你
借酒劲吻你 2020-12-13 11:31

I am doing the following inside a make file

pushd %dir_name%

and i get the following error

/bin/sh : pushd : not foun         


        
11条回答
  •  爱一瞬间的悲伤
    2020-12-13 12:26

    This is because pushd is a builtin function in bash. So it is not related to the PATH variable and also it is not supported by /bin/sh (which is used by default by make. You can change that by setting SHELL (although it will not work directly (test1)).

    You can instead run all the commands through bash -c "...". That will make the commands, including pushd/popd, run in a bash environment (test2).

    SHELL = /bin/bash
    
    test1:
            @echo before
            @pwd
            @pushd /tmp
            @echo in /tmp
            @pwd
            @popd
            @echo after
            @pwd
    
    test2:
            @/bin/bash -c "echo before;\
            pwd; \
            pushd /tmp; \
            echo in /tmp; \
            pwd; \
            popd; \
            echo after; \
            pwd;"
    

    When running make test1 and make test2 it gives the following:

    prompt>make test1
    before
    /download/2011/03_mar
    make: pushd: Command not found
    make: *** [test1] Error 127
    prompt>make test2
    before
    /download/2011/03_mar
    /tmp /download/2011/03_mar
    in /tmp
    /tmp
    /download/2011/03_mar
    after
    /download/2011/03_mar
    prompt>
    

    For test1, even though bash is used as a shell, each command/line in the rule is run by itself, so the pushd command is run in a different shell than the popd.

提交回复
热议问题