Skip to content

Commit

Permalink
Add kj4ezj/echo-eval (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
kj4ezj committed Feb 21, 2024
1 parent 596954f commit 6ada1aa
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions _posts/2024-02-06-echo-eval.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
layout: post
title: "echo-eval"
description: "Debug systems faster when logs look like terminal output."
category: ci
tags: [bash, ci, cli, command wrappers, debugging, lib, library, logs, server, testing]
---

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
jq-1.6
```
This pattern minimizes the time it takes to debug your bash systems by leaving logs resembling someone typing at a terminal.

## Installation
You can install this globally...
```bash
sudo bpkg install -g kj4ezj/echo-eval
```
...or as a project dependency.
```bash
bpkg install kj4ezj/echo-eval
```
If you install it as a `bpkg` dependency then you will need to source it in your scripts.
```bash
source deps/bin/ee
```
Your paths may vary.

## Usage
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...
```bash
ee uname
```
...looks like this on Linux.
```
$ uname
Linux
```
You can invoke `ee` as a function...
```bash
ee echo test
```
...or as a file.
```bash
./ee.sh echo test
```
Some commands may need to be encased in quotes to work the way you intend. For example, `dc` is sensitive to whitespace.
```bash
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'
3
```
In this example, we want the input to `ee` to include the pipe (`|`).
```bash
echo-eval$ export EXAMPLE='yeet'
echo-eval$ ee printf "$EXAMPLE" | wc -c
18
echo-eval$ ee 'printf "$EXAMPLE" | wc -c'
$ printf "$EXAMPLE" | wc -c
4
```
Quotes were needed to get the correct output of four characters.

## Links
Written by [Zach Butler](https://github.com/kj4ezj).
- [Source Code](https://github.com/kj4ezj/echo-eval) - GitHub
- [Documentation](https://github.com/kj4ezj/echo-eval#echo-eval)

Check out the GitHub repo for more information.

{% include JB/setup %}

0 comments on commit 6ada1aa

Please sign in to comment.