Reputation: 103
I'm trying to record all user input into the terminal to a file, so that it can be executed later.
I don't think I want to use script
or asciinema
package as the output includes lots of noise that is hard to execute again. Although if you can instruct how to clean up the output from those that'd be great to.
I am able to save all user input, except interactive inputs, into recording.txt
, with this:
while :
do
read -p ' → ' input
echo $input >> recording.txt
$input
done
e.g. if I run this then enter ls
, that is added to recording.txt
. However if I enter npm init
(an interactive script), only npm init
is added, not all the subsequent interactive input. Any advice on capturing everything would be greatly appreciated.
edit: by interactive I mean when you run a command and it prompts the user for more input - I want to include those inputs too.
Upvotes: 0
Views: 1258
Reputation: 4989
If you do not care too much about prompts,
tee file | bash
would give you what you want. For example:
$ tee file | bash
ls
file this
ed konijn
konijn: No such file or directory
a
wiep
.
1,$p
wiep
w
5
q
ls
file konijn this
cat konijn
wiep
gives the log in file
:
ls
ed konijn
a
wiep
.
1,$p
w
q
ls
cat konijn
Upvotes: 1