A shell script turns a repeatable command-line task into something you can run again without retyping the whole incantation. Here, Bash automates requests to the ChatPDF API: first add a PDF by URL, then use the returned source ID to ask questions about it. section 5.2
Commands can be spread across lines for sanity. In a Bash shell, a trailing backslash means the command continues on the next line—but it must be the final character. One sneaky trailing space can break the command, because computers enjoy tiny dramas. section 5.2
Upload a PDF with curl
A multiline curl command sends a POST request with an API key, JSON content type, and a document URL. A successful upload returns a sourceID, which identifies the PDF in later requests. section 5.2 section 5.2
# Read the file line by line
while IFS= read -r line; do
# Construct the command using a heredoc
command=$(cat <<EOF
curl -X POST 'https://api.chatpdf.com/v1/chats/message' \
-H 'x-api-key: sec_xxxxxx' \
-H 'Content-Type: application/json' \
-d '{
"sourceId": "src_xxxxxx",
"messages": [
{
"role": "user",
"content": "Based on the information in the PDF file at \
https://bootstrap-it.com/[...].pdf, create multi-select \
assessment questions that include the question, five \
possible answers, the correct answers (identified only \
by number), and an explanation. The questions should \
cover each of these topics: $line"
}
]
}' >> multi_select_raw
EOF
)
echo "Executing: $command"
eval "$command"
done < "$1"
This script reads an input file one line at a time, inserts each topic into a detailed prompt, and sends separate ChatPDF requests. It writes the resulting raw assessment-question output to a file, making a long manual task repeatable. section 5.2





