0

I'm trying to follow this answer, which suggesting running this command:

sudo bash -c "echo -n | openssl s_client -showcerts -connect $hostname:$port -servername $hostname \
    2>/dev/null  | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'  \
    >> $trust_cert_file_location"

But I'm getting:

syntax error near unexpected token `newline'

Now, I've figured out that it's probably because of either the > or >> operators in the command. I've found answers saying to escape such characters with quotes, but they all talk about cases when the '>' characters are a part of a simple text. What to do when it's an actual operator like in my case?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Alon
  • 10,381
  • 23
  • 88
  • 152

1 Answers1

0

Assuming you are coping some white spaces after the \.

Suggesting to remove the new line separator:

 sudo bash -c "echo -n | openssl s_client -showcerts -connect $hostname:$port -servername $hostname 2>/dev/null  | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'  >> $trust_cert_file_location"

Suggesting to test if you get all certificates or just the first one.

Dudi Boy
  • 4,551
  • 1
  • 15
  • 30