Here is my version:<p><pre><code> #!/bin/bash
printf "REPL for %s\n" "$@"
notblank()
{
[ $# -gt 0 ]
}
while true ; do
printf "%s> " "$@"
read -r || break;
notblank $REPLY || continue;
eval command \"\$@\" "$REPLY"
done
</code></pre>
We keep the original parameters and expand them with "$@". There is a Bash feature that read with no args reads the line into the REPLY variable. We want that to be subject to splitting.<p>If $REPLY expands to nothing, including multiple whitespace, then we just want to print the prompt again: not quit and not run the command with no additional arguments.<p>The eval trick allows $REPLY to undergo expansion and splitting, so that shell syntax can freely be used in the REPL.<p>Test:<p><pre><code> $ ~/test/replify/replify.sh git
REPL for git
git> rev-parse HEAD
7ac594319e417266764a6bc041b74807f2fe13bd
git> branch -r
origin/HEAD -> origin/master
origin/master
origin/origin/master
git> checkout "$TERM $TERM"
error: pathspec 'xterm xterm' did not match any file(s) known to git.
git> checkout $TERM
error: pathspec 'xterm' did not match any file(s) known to git.
</code></pre>
Cute, but not terribly useful without history recall and related features. This wants to be a feature of Bash. The regular Bash repl should have a prefix variable so it can appear to be in a sub-mode for a particular command.<p>Submit a patch for Bash to do this, and maybe you have something. Bash has a hook feature for command execution, IIRC, so this may be somehow doable without modifying Bash.
I just found out about a very similar command [1] that has more features.<p>[1] <a href="https://github.com/mchav/With" rel="nofollow">https://github.com/mchav/With</a>
It's only a REPL in the most trivial sense if it doesn't remember variables or results between commands. I suppose it would be easy to store the output in $LAST or $R1, $R2, ..., and then eval the input.
Another generic `repl` utility, this one in ruby: <a href="https://github.com/defunkt/repl" rel="nofollow">https://github.com/defunkt/repl</a>
Neat trick - the only change I made is to exit the while loop by typing "exit". That way the enter key runs the command with no arguments, and you can exit with control+c or by typing "exit".