Debug systems faster when logs look like terminal output.

This minimalist library takes a bash command as a string, prints it with a shell prompt in front of it, then runs that command using eval.

$ jq --version

This pattern minimizes the time it takes to debug your bash systems by leaving logs resembling someone typing at a terminal.


You can install this globally…

sudo bpkg install -g kj4ezj/echo-eval

…or as a project dependency.

bpkg install kj4ezj/echo-eval

If you install it as a bpkg dependency then you will need to source it in your scripts.

source deps/bin/ee

Your paths may vary.


This library takes the input you give it, prints or echoes it to the terminal with a fake shell prompt in front of it, then tries to run it as a command. For example, the output of this…

ee uname

…looks like this on Linux.

$ uname

You can invoke ee as a function…

ee echo test

…or as a file.

./ echo test

Some commands may need to be encased in quotes to work the way you intend. For example, dc is sensitive to whitespace.

echo-eval$ ee dc -e '1 2 + p'
$ dc -e 1 2 + p
dc: Could not open file 2
dc: Could not open file +
dc: Could not open file p
echo-eval$ ee "dc -e '1 2 + p'"
$ dc -e '1 2 + p'

In this example, we want the input to ee to include the pipe (|).

echo-eval$ export EXAMPLE='yeet'
echo-eval$ ee printf "$EXAMPLE" | wc -c
echo-eval$ ee 'printf "$EXAMPLE" | wc -c'
$ printf "$EXAMPLE" | wc -c

Quotes were needed to get the correct output of four characters.

Written by Zach Butler.

Check out the GitHub repo for more information.

blog comments powered by Disqus