Read from a named pipe

?
S
Bash

Example of how to read commands from a named pipe.

1##### read_cmd.sh #####
2#! /usr/bin/env bash
3pipe=/path/to/pipe
4[ -p "$pipe" ] || mkfifo -m 0600 "$pipe" || exit 1
5while :; do
6    while read -r cmd; do
7        if [ "$cmd" ]; then
8            printf 'Running %s ...\n' "$cmd"
9            # sh -c "$cmd" sh
10        fi
11    done <"$pipe"
12done
13
14##### alternative.sh #####
15#! /usr/bin/env bash
16tail -f $pipe | sh & 
17
18
19##### readline.sh #####
20#!/bin/bash
21while read line; do
22  echo "reading: ${line}"
23  echo $line > /tmp/srv-input
24  # node queue-broker/index.js ${line}
25done < /dev/stdin
26

Created on 2/15/2018