bash multiple heredocs et al
In this case you could consider using bash
with its -s
argument:
sudo -u buildmaster bash -s -- "$PARAMETER" <<'END'# do all sorts of crazy stuff here including using variables, like:ARGS=somethingARGS="$ARGS or other"# and so forthPARAMETER=$1END
(note that you have a syntax error, your closing END
is quoted and shouldn't be).
There's another possibility (so that you have lots of options—and this one might be the simplest, if it applies) is to have your variables exported, and use the -E
switch to sudo
that exports the environment, e.g.,
export PARAMETERsudo -E -u buildmaster bash <<'EOF'# do all sorts of crazy stuff here including using variables, like:ARGS=somethingARGS="$ARGS or other"# and so forth# you can use PARAMETER here, it's fine!EOF
Along these lines, if you don't want to export everything, you may use env
as follows:
sudo -u buildmaster env PARAMETER="$PARAMETER" bash <<'EOF'# do all sorts of crazy stuff here including using variables, like:ARGS=somethingARGS="$ARGS or other"# and so forth# you can use PARAMETER here, it's fine!EOF