0

I first define

#+NAME: 01H7T457WEWS07WD5T05BS5CN9
#+begin_src shell :results verbatim replace drawer :wrap src json
echo "foo"     
#+end_src

#+RESULTS: 01H7T457WEWS07WD5T05BS5CN9
#+begin_src json
foo
#+end_src

..and run it

#+begin_src shell :var _01H7STDXTTPR3GVA6ZJFCBJTWD=01H7T457WEWS07WD5T05BS5CN9 :results verbatim :noweb yes
curl -v 'https://gnu.org/test' \
     -H "Content-Type: application/json" \
     -H 'Authorization: Bearer '$_01H7STDXTTPR3GVA6ZJFCBJTWD''
#+end_src

, and I get

curl: (3) URL rejected: No host part in the URL

However, if I define within, it works fine.

#+begin_src shell :results verbatim
export _01H7T457WEWS07WD5T05BS5CN9="foo"
curl -v 'https://gnu.org/test' \
     -H "Content-Type: application/json" \
     -H 'Authorization: Bearer '$_01H7T457WEWS07WD5T05BS5CN9''
#+end_src

I'm not really sure what's happening here;) Am I typing it wrong?

6
  • I cannot reproduce it: both curl shell blocks produce the same output for me: #+RESULTS: : <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> : <html><head> : <title>301 Moved Permanently</title> : </head><body> : <h1>Moved Permanently</h1> : <p>The document has moved <a href="https://www.gnu.org/test">here</a>.</p> : <hr> : <address>Apache/2.4.29 Server at gnu.org Port 443</address> : </body></html>
    – NickD
    Commented Aug 14, 2023 at 15:12
  • Yes, it works, but this message is displayed in stderr, which is a window that pops up. Do you have a curl stderr window popping up? Commented Aug 14, 2023 at 16:21
  • What works? This message is the stdout of the command, not the stderr (do the commands in a terminal and see). I got rid of the -v which obscured the error output. The first one does indeed fail (with a different message: curl: (3) URL using bad/illegal format or missing URL) but that's because the value of the env variable includes a trailing newline. Do C-c C-v C-v on each code block to see what it expands to and cut and paste that into a terminal to debug.
    – NickD
    Commented Aug 14, 2023 at 16:42
  • Use echo -n "foo" in the first code block.
    – NickD
    Commented Aug 14, 2023 at 16:53
  • Ah, there is a newline appended to the end of it;) How come? Commented Aug 16, 2023 at 12:15

1 Answer 1

0

There is a newline appended, so to remove the newline:

#+begin_src shell :var VFY4O4ap1bRqbadlm7Rhe=W2rVuySIKascv2KRq6zY7 :results verbatim
curl -v 'https://gnu.org/test' \
     -H "Content-Type: application/json" \
     --header 'Authorization: Bearer '`echo $_01H7STDXTTPR3GVA6ZJFCBJTWD|tr -d '\n'`'' \
#+end_src

or use -n, as suggested;)

2
  • Or use echo -n as I suggested in a comment.
    – NickD
    Commented Aug 16, 2023 at 13:04
  • yup, or that;), thanks Commented Sep 13, 2023 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.