title: How can I redirect a string to replace the STDIN_FILENO file descriptor?
body: <p>I'm currently trying to write my own bash shell, and input output redirection works fine, but I'm having trouble implementing "&lt;&lt;&lt;".</p>
  
  <p>For example, if I type <code>cat &lt;&lt;&lt; "Hello world"</code>, it should display "Hello world".</p>
  
  <p>For the other io redirectors like &lt; and >, I've been using the open and dup system calls, but it won't work for this, unless I create a temporary text file.</p>
  
  <p>Is there a way to do this without creating a temporary file?</p>
  
  <p>I tried</p>
  
  <pre><code>int fd[2];
  pipe(fd);
  write(fd[1], string, strlen(string));
  dup2(fd[1], 0);
  </code></pre>