How to fill in command line input

I am running a bash script, and I would like to pre-populate the command line with some command after the script is executed. The only condition is that the script should not work at this time.

I need...

  • run the script
  • prefilled the text on my command line AFTER the script was stopped

Is it possible? All I tried was to simulate a bash script using

read -e -i "$comm" -p "[ $USER@ $HOSTNAME $PWD]$ " input command $input 

But I'm looking for something more direct.

+6
source share
1 answer

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.

+9
source

Source: https://habr.com/ru/post/917265/


All Articles