The -s option silences progress, -o /dev/null discards output, and -w "%{http_code}" prints the HTTP status code.
Step 2: Analyze the URL and expected status
The URL https://httpbin.org/status/200 returns HTTP status 200, so the variable response will hold "200".
Final Answer:
200 -> Option A
Quick Check:
HTTP status code = 200 [OK]
Hint: Use -w "%{http_code}" to get HTTP status code [OK]
Common Mistakes:
Expecting full page content instead of status code
Missing quotes around %{http_code}
Not using -s to silence output
4. Identify the error in this script snippet:
curl -X POST -d 'name=John' https://example.com/api
if [ $? -eq 0 ]; then
echo "Success"
else
echo "Failed"
fi
medium
A. No error; script works correctly
B. Missing quotes around URL
C. Single quotes prevent variable expansion in -d
D. Using -X POST with -d is invalid
Solution
Step 1: Check curl command syntax
The command uses -X POST with -d 'name=John' correctly to send POST data.
Step 2: Verify script logic for success check
The script checks the exit status $? properly and echoes success or failure accordingly.
Final Answer:
No error; script works correctly -> Option A
Quick Check:
Script syntax and logic = correct [OK]
Hint: Check exit status $? after curl for success [OK]
Common Mistakes:
Thinking single quotes block variable expansion here (no variables used)
Assuming -X POST and -d can't be combined
Forgetting to check curl exit status
5. You want to write a bash script that sends a JSON POST request with curl to https://api.example.com/data and saves the response to response.json. Which script snippet correctly does this?
hard
A. curl -X POST -H 'Content-Type: application/json' -d '{key:value}' https://api.example.com/data >> response.json
C. curl -X POST -H Content-Type application/json -d '{"key":"value"}' https://api.example.com/data > response.json
D. curl -X POST -H 'Content-Type: application/json' -d '{"key":"value"}' https://api.example.com/data > response.json
Solution
Step 1: Check HTTP method and headers
curl -X POST -H 'Content-Type: application/json' -d '{"key":"value"}' https://api.example.com/data > response.json correctly uses -X POST and sets the header -H 'Content-Type: application/json' with quotes.
Step 2: Validate JSON data and output redirection
curl -X POST -H 'Content-Type: application/json' -d '{"key":"value"}' https://api.example.com/data > response.json uses valid JSON with escaped quotes and redirects output with > to overwrite response.json.
Step 3: Identify errors in other options
curl -POST -H 'Content-Type: application/json' -d '{key:value}' https://api.example.com/data > response.json uses invalid -POST flag and unquoted JSON keys. curl -X POST -H Content-Type application/json -d '{"key":"value"}' https://api.example.com/data > response.json misses quotes around header value. curl -X POST -H 'Content-Type: application/json' -d '{key:value}' https://api.example.com/data >> response.json appends with >> and has invalid JSON keys.
Final Answer:
curl -X POST -H 'Content-Type: application/json' -d '{"key":"value"}' https://api.example.com/data > response.json -> Option D
Quick Check:
Correct POST JSON syntax and output redirection = curl -X POST -H 'Content-Type: application/json' -d '{"key":"value"}' https://api.example.com/data > response.json [OK]
Hint: Use -H for headers, -d with valid JSON, > to save output [OK]
Common Mistakes:
Forgetting quotes around JSON keys and values
Using invalid curl flags like -POST
Appending instead of overwriting output file
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.