6 ms·
This is a prime example of useless use of cat. Heredoc already means "pass this as stdin", there's no need to pipe it. Your example without cat: curl http:
by lotheac 12y ago
This is a prime example of useless use of cat. Heredoc already means "pass this as stdin", there's no need to pipe it. Your example without cat:
curl http://localhost -d @- <<REQUEST_BODY
{
"from" : 0,
"size" : 40
}
REQUEST_BODY
- mateuszf 12y agoWell, maybe in that case it is. But I like to separate the commands so that the data flow looks sequential. That way it makes more sense to me.
- zimpenfish 12y agoMuch as I hate the cargocult invocation of "UUOC", this is actually nicer because it reads more sanely - the HEREDOC is properly linked to the curl whereas the previous has the curl seemingly adrift on its own line unattached to the HEREDOC.
- pdkl95 12y agoI like modularity: request_body() { cat <<REQUEST_BODY | { "from" : 0, "size" : 40 } REQUEST_BODY } get_url() { curl http://localhost -d @- } request_body | get_url I find it helps readability when you come back to it a year later. Of course, it's also easy to parameterize the body, if needed. /readability sometimes trumps YAGNI