Makefile - Why is the read command not reading the user input?

Viewed 17084

I have the following code inside a 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

However when typing anything (eg. "asd") this is what gets returned:

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

asd
oot_path
Error: Could not find that location!

When what I would expect to see would be:

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

asd
asd
Error: Could not find that location!

How do I fix this???

2 Answers

Using .ONESHELL makes multiline commands easier to read then using ';' and '\' to separate lines:

.ONESHELL:
my-target:
  echo "What is the root directory of your webserver? Eg. ~/Server/htdocs"
  read root_path
  echo $$root_path

I don't have enough karma to post comments, therefore an answer (which should've been a comment to the accepted answer):

Related