Skip to content

Instantly share code, notes, and snippets.

@pwalkr
Last active July 23, 2022 17:13
Show Gist options
  • Save pwalkr/bb7c3eafd5b9a4694bd52282f46a7f3f to your computer and use it in GitHub Desktop.
Save pwalkr/bb7c3eafd5b9a4694bd52282f46a7f3f to your computer and use it in GitHub Desktop.
Echo-evaluate individual commands
#!/bin/sh
eeval () {
set -x
"$@"
{ set +x; } 2>/dev/null
}
# Print command and evaluate
eeval touch file
# Not printed to terminal
rm file
@pwalkr
Copy link
Author

pwalkr commented Jul 23, 2022

This highlights the "don't print set +x" trick from https://stackoverflow.com/a/19226038

Using set -x ensures a command is printed with any spaces and special characters properly escaped. I frequently don't want every interpreted step to be printed, e.g. conditionals and loops, hence a per-command "echo-eval" wrapper function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment