Makefile - 为什么读取命令不读取用户输入?

2024-04-06

我的 Makefile 中有以下代码:

# Root Path
echo "What is the root directory of your webserver? Eg. ~/Server/htdocs" ;
read root_path ;
echo $root_path ;
if [ ! -d $root_path ] ; then \
    echo "Error: Could not find that location!" ; exit 1 ; \
fi

但是,当输入任何内容(例如“asd”)时,将返回以下内容:

What is the root directory of your webserver? Eg. ~/Server/htdocs

asd
oot_path
Error: Could not find that location!

当我期望看到的是:

What is the root directory of your webserver? Eg. ~/Server/htdocs

asd
asd
Error: Could not find that location!

我该如何解决???


眼前的问题是 Make 本身解释了$与外壳不同。尝试:

    echo "What is the root directory of your webserver? Eg. ~/Server/htdocs"; \
    read root_path; \
    echo $$root_path

$$逃脱了$对于 Make,所以它通过了单个$到外壳。另请注意,您将需要使用\行延续,以便整个序列作为一个 shell 脚本执行,否则 Make 将生成一个new每行的外壳。这意味着任何你read一旦它的外壳退出就会消失。

我还想说,一般来说,提示从 Makefile 进行交互式输入的情况并不常见。您最好使用命令行开关来指示 Web 服务器根目录。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Makefile - 为什么读取命令不读取用户输入? 的相关文章

随机推荐