You can use Perl and the IO::Prompter module. Here's a script that should help
#!/usr/bin/perl -w use IO::Prompter<<EOF; echo "Hello world!" ls ls -l ls -l | sort EOF use strict; use feature 'say'; use IPC::Open2; use Time::HiRes 'sleep'; open2('>&STDOUT',\*SHELL,'bash'); while(my $cmd=prompt '$'){ say SHELL $cmd; sleep 0.05; }
This script gives you a prompt (configurable, just edit the argument to prompt
) and each keystroke inserts a character from the command block above. Backspace works too, and you can also press enter and IO::Prompter will auto-complete the line and send it to bash at a reasonable writing speed. After running the commands from the command block, the script will continue to accept any input and will send it to bash.
You should have Perl already installed. To install IO::Prompter, run cpan IO::Prompter
from your favourite terminal emulator.