-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |