在Linux中的$$

我有一个make文件中的以下代码,我知道如果不存在,它将在Home中创建bin文件夹...但是我不明白$ HOME / bin是什么意思...

我在Google上搜索后发现$$是要获取bash的进程ID ...但是无法理解$$ HOME / bin是什么意思...有人可以解释一下吗?

.PHONY: home_bin
home_bin: ## Create home bin if not created
    @ if [[ ! -d "$$HOME/bin" ]]; then \
        echo "Creating $$HOME/bin"; \
        mkdir $$HOME/bin; \
        echo "✔︎ $$HOME/bin created"; \
    else \
        echo "✔︎ $$HOME/bin already created"; \
    fi

谢谢。

评论
iullam
iullam

make itself performs expansion of $-prefixed characters; the $$ is expanded to a single literal $ to pass to the shell.

考虑一个简单的Makefile:

x=f

all:
        xoo=3 && echo $xoo

which will output foo, because

  1. make expands $x to the single character f.
  2. make passes the string xoo=3 && echo foo to the shell for execution

与之比较

x=f

all:
        xoo=3 && echo $$xoo

which outputs 3, because

  1. make expands $$ to $
  2. make passes the string xoo=3 && echo $xoo to the shell for execution
点赞
评论