yu nkt’s blog

nkty blog

I'm an enterprise software and system architecture. This site dedicates sharing knowledge and know-how about system architecture with me and readers.

Makefile内のechoコマンドで$ (ダラー)をそのまま出力させる

Makefile内のechoコマンドで$ (ダラー)をそのまま出力させる方法です。 全く情報を見つける事が出来ませんでしたが、試行錯誤してたら出来ました。

環境:bash (バージョン:4.2.46(2)-release (x86_64-redhat-linux-gnu))

Makefileにこのように書きます。

build:
    @echo Current '$$'http_proxy is ${http_proxy}

(インデントはタブにしてください。はてブの都合上、タブに出来ない…)

ポイントは、$$を、シングルクオーテーションで囲むところです。 囲まないと、次のhttp_proxyの環境変数の値が表示されてしまいます。

では、実行してみます。

$ export http_proxy=http://huga
$ make build
Current $http_proxy is http://huga

ちゃんと、$が表示されました。