I would like to write a perl script that do something similar to what fc do. Indeed I want to edit programmatically the last command executed. Something like this should work
perl -wle 'print system("/bin/bash", "-i", "-c", "history | tail -n 1")'
but system
return the exit status of the command executed, not the stdout, that is what I want, while I'm not able to activate the history (-i
flag) using back-tic, qx//
or opening a pipe.
I know that using back-tic, qx//
or opening a pipe it is simple to read the stdout of the command, but int this case how to use the builtin bash hisotry
command properly?
Even using system
and passing -i
to bash, I'm not able to get the expected output from history | tail -n 1
. Bi redirecting the output to a file I found its content empty.
perl -wle 'print system("/bin/bash", "-i", "-c", "history | tail -n 1 > /tmp/pippo")'
So am I forced to write the bash history on a file whit history -w
and to read that file inside perl?