How to "inject" lines into a redirect here doc?
I have a BASH function execute
that establishes a SSH connection to a machine and runs a bunch of commands provided here by redirecting the doc. This works great. Is there a way to insert some commands into the redirect? I would like to always run prepare_something
before eg do_something
.
function execute() {
ssh user@host /bin/bash
}
execute << EOF
do_something
EOF
+3
Lars schneider
source
to share
1 answer
You can use a subshell to combine echo with cat
that consumes stdin functions. Then the subshell output will become the input of your ssh command.
function execute() {
( echo prepare_something ; cat ) | ssh user@host /bin/bash
}
+1
Bill karwin
source
to share