0
0
Bash Scriptingscripting~20 mins

HTTP requests with curl in scripts in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Curl Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this curl command?
You run this command in a terminal to get the HTTP status code of a website:

curl -o /dev/null -s -w "%{http_code}" https://example.com

What will this command output?
Bash Scripting
curl -o /dev/null -s -w "%{http_code}" https://example.com
AThe full HTML content of https://example.com
B200
CAn error message about missing output file
DNothing (blank output)
Attempts:
2 left
💡 Hint
The flags -o /dev/null and -s hide the content and progress, -w "%{http_code}" prints the status code.
💻 Command Output
intermediate
2:00remaining
What does this curl command output?
This command sends a POST request with JSON data:

curl -X POST -H "Content-Type: application/json" -d '{"name":"Alice"}' https://httpbin.org/post

What kind of output will you get?
Bash Scripting
curl -X POST -H "Content-Type: application/json" -d '{"name":"Alice"}' https://httpbin.org/post
ANo output, command runs silently
BThe HTML page of httpbin.org homepage
CA JSON response showing the data sent and request details
DAn error about unsupported HTTP method
Attempts:
2 left
💡 Hint
httpbin.org/post echoes back the POST data in JSON format.
🔧 Debug
advanced
2:00remaining
Why does this curl command fail with a certificate error?
You run this command:

curl https://self-signed.badssl.com/

It fails with an SSL certificate error. Which option fixes this error by ignoring certificate validation?
Bash Scripting
curl https://self-signed.badssl.com/
Acurl --insecure https://self-signed.badssl.com/
Bcurl --no-ssl https://self-signed.badssl.com/
Ccurl --ignore-certs https://self-signed.badssl.com/
Dcurl --skip-verify https://self-signed.badssl.com/
Attempts:
2 left
💡 Hint
The option to ignore SSL certificate errors is --insecure or -k.
🚀 Application
advanced
2:00remaining
How to save HTTP response headers to a file using curl?
You want to save only the HTTP response headers from a GET request to https://example.com into a file named headers.txt. Which command does this correctly?
Acurl -D headers.txt https://example.com -o /dev/null
Bcurl -H headers.txt https://example.com
Ccurl -I https://example.com > headers.txt
Dcurl --headers https://example.com > headers.txt
Attempts:
2 left
💡 Hint
The -D option saves headers to a file; -o /dev/null discards the body.
🧠 Conceptual
expert
2:00remaining
What is the effect of this curl command in a script?
Consider this bash script snippet:

response=$(curl -s -w "%{http_code}" -o response.txt https://example.com)

What will be stored in the variable response after running this command?
Bash Scripting
response=$(curl -s -w "%{http_code}" -o response.txt https://example.com)
AAn empty string
BThe full HTML content of https://example.com
CThe path to the saved file response.txt
DThe HTTP status code as a string, e.g., "200"
Attempts:
2 left
💡 Hint
The -w option outputs the status code to stdout, -o saves body to file, -s silences progress.