You need to use TIOCSTI ioctl. Here is an example C program that shows how this works:
#include <sys/ioctl.h> main() { char buf[] = "date"; int i; for (i = 0; i < sizeof buf - 1; i++) ioctl(0, TIOCSTI, &buf[i]); return 0; }
Compile this and run it, and "date" will be buffered as an input to stdin, which your shell will read after the program exits. You can collapse this into a command that allows you to input something into the input stream and use this command in a bash script.
source share