I would find very useful a shell script or program to emulate a "shell" for a program by repeatedly taking input arguments and running the program with them.
e.g. I would run `shellemulator some-non-interactive-console-calculator-or-something`
and it would send each line of subsequent input to some-non-interactive-console-calculator-or-something, until I exit it somehow.
So for the calculator example above, I could just type an equation and press enter, instead of typing the full command to run the calculator each time.
Here's an example that doesn't demonstrate how useful it would really be
Instead of running:
Code: Select all
/lmp-0.2.99.10/src# ./lmp --vartable="pi=3.14159" 6+4*pi
18.56636
/lmp-0.2.99.10/src# ./lmp 6+4*3*sin45
16.210842
/lmp-0.2.99.10/src# ./lmp --vartable="pi=3.14159" 6+4*pi*3*sin45
38.07828
Code: Select all
/lmp-0.2.99.10/src# shellemulator ./lmp --vartable="pi=3.14159"
6+4*pi
18.56636
6+4*3*sin45
16.210842
6+4*pi*3*sin45
38.07828
I could write an infinite loop to repeatedly run `rxvt -e something`, but I want to repeatedly use the same terminal so the user can see the argument and output history, and (hopefully) scroll through arguments with the arrow keys, just as they can scroll through the command history in rxvt.
BTW I did look for an existing program or script to do this, and I didn't find anything - but it's the sort of thing I don't have a good track record of finding
--------------
EDIT - wait a minute, I found this http://www.soyo123.com/shell-en/20080308/307.html
I'm just making it more generic...
It is just what I want, except it doesn't have a scrollable argument history
-------------
EDIT - here's a preliminary version
Code: Select all
#!/bin/sh
# shellemulator - emulates a "shell" for a program by repeatedly taking input arguments and running the program with them.
# e.g. allows sort-of "interactive" use of a non-interactive calculator.
# By disciple 28/10/08
# http://murga-linux.com/puppy/viewtopic.php?p=243877#243877
# Based on code from http://www.soyo123.com/shell-en/20080308/307.html
# Would be nice to be able to scroll through the argument history.
# Would be nice to add support for setting "environment variables".
# Would be nice to automatically store the output of the last command in an "answer" or "output" variable (e.g. for a calculator to use the results of the previous command).
# Could add ability to edit $command (or at least add extra arguments), but there is little point as it is just as easy to simply quit and edit the command we ran this script with.
helptext="shellemulator - emulates a 'shell' for a program by repeatedly taking input arguments and running the program with them. Enter 'help' for this text, 'quit' to quit."
command="$@"
echo "
$helptext
"
echo -n "$command> "
while read arguments
do
case $arguments
in
quit|exit) exit 0 ;;
help|\?) echo "$helptext" ;;
*) $command "$arguments" ;;
esac
echo -n "
$command> "
done
echo ""
exit 0