0

I fear I am going to have to restructure this entirely, but can anyone tell me why this used to work and now it does not in the latest Macos BASH?

Works: GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)

Does Not Work: GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)

urlfile="$1"
IFS=$(echo -e '\n')
while IFS= \
read -r var1; \
read -r var2
do

curl -g --request POST \
  --url https://website.com/urlLookup \
  --header 'Content-Type: application/json' \
  --header 'cache-control: no-cache' \
  --data '[
"'"$var1"'",
"'"$var2"'"]' \
  --cookie newcookies.txt

sleep 10
echo " "
done <"$urlfile"

The set -x shows the error and it looks like it might be a be a BASH bug. The variable has an accept-line "\C-M/"included in it.

curl -g --request POST --url https://replaced.com/urlLookup --header 'Content-Type: application/json' --header 'cache-control: no-cache' --data $'["art.com\C-M/"]' --cookie newcookies.txt

I have tried every combination I can think of... The format has to be '["art.com"]' for it to be accepted. The single quotes have to be there or the variable is not populated... '['"$var1"']', but as soon as this is done the accept line shows up.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Todd
  • 1
  • 1
  • 3
    **"and now it does not"**; what doesn't work? Any errors? – 0stone0 Apr 07 '21 at 22:49
  • 1
    Put `set -x` before the problem section to get a trace of what's happening, and see what's different. – Gordon Davisson Apr 07 '21 at 23:27
  • BTW, what're the exact system versions you're using? "darwin18" indicates macOS v10.14.something, but the exact version and build (use `sw_vers`) might help. – Gordon Davisson Apr 08 '21 at 00:34
  • The quotes around the variables is where the problem is. This works... – Todd Apr 08 '21 at 13:10
  • 1
    The evidence suggests that you added DOS carriage returns to the file when you copied it over, and both versions of Bash work fine as such. – tripleee Apr 08 '21 at 15:40
  • Your question should remain strictly a question. Going forward, please don't make edits which add answer attempts or other commentary. – tripleee Apr 08 '21 at 15:41
  • Thanks tripleee... Yeah I was a little lost on how to respond. Just to be clear I just click ask question to respond to the comments? I also didn't find a solution as I thought, can I reopen this question, or restart a new one? – Todd Apr 08 '21 at 16:02
  • If you can edit the question to demonstrate that it's not a duplicate, I'll be happy to reopen it. Then you'll be able to post an answer with your findings, and eventually accept it. Please feel free to ping me in a comment (like @tripleee with no space between the @ and my user name) once you have made those edits if you would like to do that. – tripleee Apr 08 '21 at 16:05
  • Thank you... No need to reopen, you were correct about the CR. I created a new file and it worked fine. I had checked to make sure there wasn't any spaces at the end, but I guess I need to research how to show all formatting. Thank you again, and please excuse the newby issues. – Todd Apr 08 '21 at 16:10
  • No problem. As an aside, your IFS assignments are weird; if you want a newline, `IFS=$'\n'` does that without the pesky command substitution, but you end up replacing it with an empty value immediately after. There are several common FAQs about interpolating variables into JSON strings for submitting them with `curl`; probably search a few to get a better understanding of how exactly the quoting works there. For example, try https://stackoverflow.com/questions/17029902/using-curl-post-with-variables-defined-in-bash-script-functions – tripleee Apr 08 '21 at 16:18

0 Answers0