Output content to stdout
and HTTP status to stderr
:
curl -s http://www.example.org -o >(cat >&1) -w "%{http_code}" 1>&2
For example:
cat > /tmp/demo.sh <<EOF
#!/bin/bash
{
curl -s http://www.example.org -o >(cat >&1) -w "%{http_code}" 1>&2
} 1>/tmp/out 2>/tmp/err
echo -e "stdout was $(wc -c</tmp/out) chars and began with: $(head -c16 /tmp/out)"
echo -e "stderr was $(wc -c</tmp/err) chars and began with: $(head -c16 /tmp/err)"
EOF
chmod +x /tmp/demo.sh
/tmp/demo.sh
stdout was 1270 chars and began with: <!doctype html>
stderr was 3 chars and began with: 200