|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "echo-eval" |
| 4 | +description: "Debug systems faster when logs look like terminal output." |
| 5 | +category: ci |
| 6 | +tags: [bash, ci, cli, command wrappers, debugging, lib, library, logs, server, testing] |
| 7 | +--- |
| 8 | + |
| 9 | +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`. |
| 10 | +``` |
| 11 | +$ jq --version |
| 12 | +jq-1.6 |
| 13 | +``` |
| 14 | +This pattern minimizes the time it takes to debug your bash systems by leaving logs resembling someone typing at a terminal. |
| 15 | + |
| 16 | +## Installation |
| 17 | +You can install this globally... |
| 18 | +```bash |
| 19 | +sudo bpkg install -g kj4ezj/echo-eval |
| 20 | +``` |
| 21 | +...or as a project dependency. |
| 22 | +```bash |
| 23 | +bpkg install kj4ezj/echo-eval |
| 24 | +``` |
| 25 | +If you install it as a `bpkg` dependency then you will need to source it in your scripts. |
| 26 | +```bash |
| 27 | +source deps/bin/ee |
| 28 | +``` |
| 29 | +Your paths may vary. |
| 30 | + |
| 31 | +## Usage |
| 32 | +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... |
| 33 | +```bash |
| 34 | +ee uname |
| 35 | +``` |
| 36 | +...looks like this on Linux. |
| 37 | +``` |
| 38 | +$ uname |
| 39 | +Linux |
| 40 | +``` |
| 41 | +You can invoke `ee` as a function... |
| 42 | +```bash |
| 43 | +ee echo test |
| 44 | +``` |
| 45 | +...or as a file. |
| 46 | +```bash |
| 47 | +./ee.sh echo test |
| 48 | +``` |
| 49 | +Some commands may need to be encased in quotes to work the way you intend. For example, `dc` is sensitive to whitespace. |
| 50 | +```bash |
| 51 | +echo-eval$ ee dc -e '1 2 + p' |
| 52 | +$ dc -e 1 2 + p |
| 53 | +dc: Could not open file 2 |
| 54 | +dc: Could not open file + |
| 55 | +dc: Could not open file p |
| 56 | +echo-eval$ ee "dc -e '1 2 + p'" |
| 57 | +$ dc -e '1 2 + p' |
| 58 | +3 |
| 59 | +``` |
| 60 | +In this example, we want the input to `ee` to include the pipe (`|`). |
| 61 | +```bash |
| 62 | +echo-eval$ export EXAMPLE='yeet' |
| 63 | +echo-eval$ ee printf "$EXAMPLE" | wc -c |
| 64 | +18 |
| 65 | +echo-eval$ ee 'printf "$EXAMPLE" | wc -c' |
| 66 | +$ printf "$EXAMPLE" | wc -c |
| 67 | +4 |
| 68 | +``` |
| 69 | +Quotes were needed to get the correct output of four characters. |
| 70 | + |
| 71 | +## Links |
| 72 | +Written by [Zach Butler](https://github.com/kj4ezj). |
| 73 | +- [Source Code](https://github.com/kj4ezj/echo-eval) - GitHub |
| 74 | +- [Documentation](https://github.com/kj4ezj/echo-eval#echo-eval) |
| 75 | + |
| 76 | +Check out the GitHub repo for more information. |
| 77 | + |
| 78 | +{% include JB/setup %} |
0 commit comments