Last active
July 23, 2022 17:13
-
-
Save pwalkr/bb7c3eafd5b9a4694bd52282f46a7f3f to your computer and use it in GitHub Desktop.
Echo-evaluate individual commands
This file contains hidden or 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
#!/bin/sh | |
eeval () { | |
set -x | |
"$@" | |
{ set +x; } 2>/dev/null | |
} | |
# Print command and evaluate | |
eeval touch file | |
# Not printed to terminal | |
rm file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This highlights the "don't print
set +x
" trick from https://stackoverflow.com/a/19226038Using
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