Multiple command for bash shell script [duplicate]

2019-09-17 15:43发布

问题:

This question already has an answer here:

  • Bash: How to avoid warning: here-document at line XX delimited by end-of-file (wanted `EOM') [duplicate] 2 answers
  • here-document gives 'unexpected end of file' error 5 answers

I want to assign a variable after executing the set of commands The first command is to get into the shell of the openshift pod. Then cat a file and assign that to a variable outside the openshift container.

I tried it like this

check=$(oc rsh pod << EOF
cat /var/lib/jenkins/.ssh/check.pub
EOF)

It gives me an error

bash: warning: here-document at line 41 delimited by end-of-file (wanted `EOF')

回答1:

I believe the second EOF needs to be on a line by itself:

check=$(oc rsh pod << EOF 
cat /var/lib/jenkins/.ssh/check.pub 
EOF
)