0

How to get pipe data in bash functions

pacman created at4 months ago view count: 25

Use the /dev/stdin fd

examples:

do_put_s() {
  curl -s -o /dev/null -w " %{http_code}\n" -X PUT -H 'Content-Type: application/json'  http://exmaple.com -d @/dev/stdin
}

echo {"foo": "bar"}  |  do_put_s

bash

Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file. Bash also incorporates useful features from the Korn and C shells (ksh and csh).

Bash is intended to be a conformant implementation of the Shell and Utilities portion of the IEEE POSIX specification (IEEE Standard 1003.1). Bash can be configured to be POSIX-conformant by default.  

report

Comments

search keywords