I'm trying to request user input, but it's hard for me to get a read -p prompt that will print as expected when I run from the Makefile or subshell launched by the Makefile. Here are my attempts to achieve this without success:
test1: @echo '>> before input <<'; \ read -p 'type something:' FOO; \ echo '>> after input <<'; \ echo $$FOO
The result is as follows: I enter asdf . My input prints as I type, but the hint type something: prints after everything else:
$ make >> before input << asdf >> after input << asdf type something
Another way I tried is using the Bash of the readline read -e interface:
test2: @echo '>> before input <<'; \ read -e -p 'type something:' FOO; \ echo '>> after input <<'; \ echo $$FOO
In this case, the output looks good, however, neither the hint of type something: nor the actual input, as I type, is printed until I press ENTER , which is rather inconvenient when prompting for input.
I also tried to print the invitation before echo :
test3: @echo '>> before input <<'; \ echo 'input something:';\ read FOO; \ echo '>> after input <<'; \ echo $$FOO;\
And my output looks pretty good, but the input is printed on a new line:
$ make >> before input << input something: asdf >> after input << asdf
Last final using printf to avoid a new line:
test4: @echo '>> before input <<'; \ printf 'input something: ';\ read FOO; \ printf '\n'; \ echo '>> after input <<'; \ echo $$FOO;\
And it seems that read throws a prompt if it doesn't end with \n :
$ make >> before input << asdf input something: >> after input << asdf
And of course, exactly the same thing happens if I just call the script:
test5: ./script.sh
In case this helps identify the problem: OS X 10.10.3 / make 3.81 / Bash 3.2.57 (1).
Disclaimer: I know that itβs not very important to have user-dependent Makefiles, but I need this for a special case.