1

I'm trying to run a command in a command line (just copy and paste the into moba xterm to remote Ubuntu machine). The command contains a line break, so I decided to use $(command). Here is the command I am trying:

docker build -t mytag --build-arg SSH_PRIVATE_KEY=$(cat <<EOF
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAy8QlGkj4OoK4/i3Sxhpag4k/S/SsDzjMwqM2Sc5qeE2EpuqH
@#$%$#^$%&^%*&^*&^%&(&)@#$%$#^$%&^%*&^*&^%&(&)@#$%$#^$%&^%*&^*&^
@#$%$#^$%&^%*&^*&^%&(&)@#$%$#^$%&^%*&^*&^%&(&)@#$%$#^$%&^%*&^*&^
@#$%$#^$%&^%*&^*&^%&(&)@#$%$#^$%&^%*&^*&^%&(&)@#$%$#^$%&^%*&^*&^
@#$%$#^$%&^%*&^*&^%&(&)@#$%$#^$%&^%*&^*&^%&(&)@#$%$#^$%&^%*&^*&^
KaAM3nF1tnWa1YhDRxOGaq6386hEdB/i05ZFdLjfSALo56UN7mC5
-----END RSA PRIVATE KEY-----
EOF
) .

I must paste an ssh key into the command somehow.  The above command is not working; I get:

bad flag syntax: -----END
See 'docker build --help'.

1 Answer 1

3

Since the key consists of multiple words, you must put the command substitution into quotes:

docker build -t mytag --build-arg SSH_PRIVATE_KEY="$(cat << EOF
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAy8QlGkj4OoK4/i3Sxhpag4k/S/SsDzjMwqM2Sc5qeE2EpuqH
@#$%$#^$%&^%*&^*&^%&(&)@#$%$#^$%&^%*&^*&^%&(&)@#$%$#^$%&^%*&^*&^
@#$%$#^$%&^%*&^*&^%&(&)@#$%$#^$%&^%*&^*&^%&(&)@#$%$#^$%&^%*&^*&^
@#$%$#^$%&^%*&^*&^%&(&)@#$%$#^$%&^%*&^*&^%&(&)@#$%$#^$%&^%*&^*&^
@#$%$#^$%&^%*&^*&^%&(&)@#$%$#^$%&^%*&^*&^%&(&)@#$%$#^$%&^%*&^*&^
KaAM3nF1tnWa1YhDRxOGaq6386hEdB/i05ZFdLjfSALo56UN7mC5
-----END RSA PRIVATE KEY-----
EOF
)" .
2
  • You might also want to quote the heredoc to protect it from expansions: <<'EOF' May 5, 2020 at 20:07
  • Or just ... SSH_PRIVATE_KEY='multi-line string here', without a here-document.
    – Kusalananda
    May 5, 2020 at 20:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .