Metaprogramming in Bash
adam.younglogic.com
adam.younglogic.com
build_ssh qa_ssh test_ssh() {
echo ${(U)0%_*}_SYSTEMIP
}
build_ssh # Produces BUILD_SYSTEMIP
qa_ssh # Produces QA_SYSTEMIP
(You'd need the 'P' flag to perform secondary expansion to get the value of *_SYSTEMIP if you were using this for the same reason as in the post).You can even use brace expansion in your function definition, iff you define it using the function keyword like "function {build,qa,test}_ssh()".
---
There might be a nice solution to this with fish too, as you could create per-machine symlinks in your ~/.config/fish/functions to add a new machine.
(
set -x
ssh ...
)I do suspect the examples are intentionally very simplified though.
echoeval(){
CMD="$@"
echo "$ $CMD"
eval "$CMD"
}
echoeval ssh test -A
Variants that take a first parameter for coloring output, directing to stdout/stderr, or (for one-shot commands) variant that colors output based on return value -- are functions I have written.