0

I need to use a json as the command after -x in wscat. however it returns wrong format from the server.

my script is just like this:


#!/usr/bin/env bash

read -p "param1:" param1
read -p "param2:" param2

json=$(cat <<-END
{
   "param1": "${param1}",\
   "param2": "${param2}"\
}
END
)

wscat -c \<wss_host\> -x $json

this gives me error saying "invalid json request".

running sh -x <myscript>, i found i got below request in the end:
wscat -c <wss_host> -x '{' '"param1":' '"<param1 i put>",' '"param2":' '"<param1 i put>"' '}'

=> is it because my json is not parsed correctly?
i was expecting something like {"param1":"<param1 i put>","param2":"<param1 i put>"}
but not: '{' '"param1":' '"<param1 i put>",' '"param2":' '"<param1 i put>"' '}' <= there are some extra single quotes

would youd kindly advise? thank you !

yours sincerely, jiaren

i am really running out of ideas..

ren jia
  • 1
  • 1
  • what about `wscat -c \ -x "$json"` ? For your next project, copy/paste your code into https://shellcheck.net and fix any errors/warnings found there **before** posting your question here (-;! . Also, keep a link to https://stackoverflow.com/tags/bash/info handy and review the sections ***Before asking about problematic code*** and ***How to turn a bad script into a good question***. Good luck. – shellter Feb 13 '23 at 17:52
  • You need more quotes. `-x "$json"` not `-x $json` – Charles Duffy Feb 13 '23 at 18:01
  • Run your code through http://shellcheck.net/ and it would tell you this automatically. – Charles Duffy Feb 13 '23 at 18:02

0 Answers0