title: How to read just a single character in Makefile
body: <p>In a Makefile, reading user input terminated by <code>&lt;ENTER&gt;</code> can be implemented by using (the shell function) <code>read</code>. On the shell (bash), reading a single character can be done with <code>read -n 1</code>. However, I was surprised that <code>read -n 1</code> didn't seem to work with GNU Make 4.2.1. Do I miss some escaping here?</p>
  <p>Bash:</p>
  <pre><code>$&gt; echo x | read -n 1 mychar; echo 'you typed '$mychar 
  you typed x
  </code></pre>
  <p>Makefile:</p>
  <pre><code>all:
      read -n 1 mychar; echo 'you typed '$$mychar
  </code></pre>
  <p>Make:</p>
  <pre><code>$&gt; echo x | make
  read -n 1 mychar; echo 'you typed '$mychar
  /bin/sh: 1: read: Illegal option -n
  </code></pre>
  <p>Does make provide its own version of <code>read</code> ?</p>
  <p>System: GNU Make 4.2.1, Ubuntu 20.04.3 LTS</p>
  <p>PS: I am aware that user interaction is considered bad style, and it clearly should not be used in configuration workflows. However, it comes in quite handy for targets associated with pruning, resetting or deleting data (e.g., <code>make clear</code>). And asking for <code>y/N</code> confirmation gives you a chance to tell your users what it will take them to rebuild what they are going to remove.</p>
  <p>PPS: I know that the regular <code>read</code> gives you almost the same functionality, except that you need to hit <code>&lt;ENTER&gt;</code>. This question about getting a better understanding for the relationship between make and its shell enviroment.</p>
  <p>NB: This problem is different from <a href="https://stackoverflow.com/questions/3743793/makefile-why-is-the-read-command-not-reading-the-user-input">Makefile - Why is the read command not reading the user input?</a>. They just didn't properly escape the variable.</p>