To use a Bash variable for the text value in your curl command, you need to ensure the variable is expanded correctly and that the content is properly formatted, especially since you're including a multi-line string (like a Python code block).
Wrap the entire text field in single quotes and use double quotes inside the variable for the Python code block:
bashtext="print(\"test\")" curl 'URL' \ -F 'mode=comment' \ -F "text=$'```python\n\${text}\n```'"
If you use double quotes, ensure the variable is expanded and the quotes inside the variable are escaped:
bashtext='print("test")' curl 'URL' \ -F 'mode=comment' \ -F "text=\"\"\"```python\n\${text}\n```\"\"""
printf for Multi-line StringsFor more complex multi-line strings, use printf to handle newlines and quotes:
bashtext="print(\"test\")" curl 'URL' \ -F 'mode=comment' \ -F $'text=```python\n'"$text$'\n```'
text field to avoid unintended variable expansion.text field to allow expansion.text contains quotes or special characters, escape them properly.Which approach are you using for your actual use case? I can help tailor the solution further!
Le Chat can make mistakes. Check answers. Learn more