Questions tagged [process-substitution]

Process substitution a form of inter-process communication that allows the input or output of a command to appear as a file (such as: `<(cmd)` or `>(cmd)`).

Filter by
Sorted by
Tagged with
0
votes
1answer
687 views

Subshell and process substitution

Apologies if this is a basic question - I'm stuck trying to solve a larger problem, and it's come down to how a shell script is invoked - directly (shellScript.sh) or using sh shellScript.sh. Here's ...
9
votes
1answer
1k views

Process substitution in GNU Makefiles

On a bash prompt, one can execute diff using pseudo files: diff <(echo test) <(echo test) Adding this as is into a Makefile fails: all: diff <(echo test) <(echo test) The error ...
7
votes
1answer
870 views

Wait for Bash subshells

I pipe the same content to multiple commands with tee, subshells and redirects like this: #!/usr/bin/env bash echo 'hello' | tee \ >( sleep 3; cat /dev/stdin ) \ >( sleep 2; cat /dev/stdin ...
3
votes
1answer
273 views

Join two unsorted files with POSIX? [duplicate]

Because the input to join must be sorted, often the command is called similarly to: join <(sort file1) <(sort file2) This is not portable as it uses process substitution, which is not ...
1
vote
0answers
172 views

process substitution with <(gunzip …) fails

The following code returns: syntax error near ( #!/bin/bash myprogram -i <(gunzip -c file.gz) -j <(gunzip -c file2.gz) It seems it doesn't like brackets. How can I make this script work? If I ...
4
votes
1answer
129 views

Change location of zsh's process substitution ‘=()’

zsh is apparently using /tmp/zshXXXXXX to store temporary files created by the process substitution using =(). For example, $ echo =(echo test) /tmp/zsh4RmpQZ However, I would like to change the ...
0
votes
1answer
101 views

Process Substitution (e. g. $(somecommand) ) In A Nutshell

On my shell from home directory on mac, I run the following eval "ls" and this just shows me the directories. But if I run eval "$(ls)" I get the following output: zsh: command not found: ...
1
vote
1answer
405 views

Is the command in a process substitution invoked in a subshell?

From the bash manual Process substitution is supported on systems that support named pipes (fifos) or the /dev/fd method of naming open files. It takes the form of <(list) or >...
3
votes
1answer
167 views

Why ssh immediately disconnects when using -F /dev/stdin syntax?

I've configured and booted default Ubuntu VM box by the following commands: vagrant init ubuntu/trusty64; vagrant up --provider virtualbox Now, for education purposes, I'd like to use the following ...
1
vote
1answer
605 views

Piping multiple inputs into Ghostscript

I am trying to create a one-line Linux command to combine two PDF files - which are downloaded from a URL - using Ghostscript. However, I do not want to create any temporary files (everything should ...
1
vote
1answer
440 views

Bash Process Substitution in exec line, some commands stopped working

So I have a bash command using process substitution in an exec line that stopped working recently, and it boils down to this example: Contents of script.sh: #!/bin/bash ls -l "$1" >/tmp/out ...
13
votes
1answer
854 views

How to emulate Process Substitution in Dash?

In bash, I can use Process Substitution and treat output of a process as if it was a file saved on disk: $ echo <(ls) /dev/fd/63 $ ls -lAhF <(ls) lr-x------ 1 root root 64 Sep 17 12:55 /dev/fd/...
24
votes
1answer
2k views

What is the portable (POSIX) way to achieve process substitution?

Some shells, like bash, support Process Substitution which is a way to present process output as a file, like this: $ diff <(sort file1) <(sort file2) However, this construct isn't POSIX and, ...
1
vote
1answer
325 views

Can Bash process substitution be used as part of argument expansion?

I'm familiar with process substitution used the canonical way, e.g. diff <(ls /folder1) <(ls /folder2) However, can it be used when the process asks for an argument that is not just the path ...
2
votes
2answers
236 views

Build a process substitution list for tee

I have a script like this which I use to broadcast commands to several instaces of the postgresql database CLI connected to several different servers. I'm using a hard-coded set of process-...
1
vote
3answers
208 views

Implementation of process substitution, and concurrency in process substitution

Bash Manual says Process substitution is supported on systems that support named pipes ( fifos) or the /dev/fd method of naming open files. Does it mean that process substition is implemented ...
1
vote
1answer
110 views

Persistent process substitutions? [duplicate]

Is there a way to take a process substitution like <(grep foo some/file), and save it to a "file-like entity" on disk (reminiscent of a fifo), so that, every time this thing was opened for reading ...
1
vote
1answer
312 views

error:too many words `` in cat

I have a csv file that auto-generate with filename format yy-mm-dd_h. The csv file content: Status Filename 1 1A-W02_ws_r0_apr13_15_44.stdf 1 2A-W04_ws_r1_apr12_10_30.stdf 1 1A-...
11
votes
3answers
12k views

Failed to open config file '/dev/fd/63', error: No such file or directory for wpa_supplicant

When I do this: sudo wpa_supplicant -D nl80211,wext -i wlp4s0 -c <(wpa_passphrase "some ssid" "password") I get Successfully initialized wpa_supplicant Failed to open config file '/dev/fd/63', ...
4
votes
2answers
767 views

How do you implement process substitution (using a bash script) in a shell that doesn't have it?

I've seen Fish shell implement process substitution as a function: # === Fish shell lang: function psub mkfifo $the_pipe cat >$the_pipe & echo $the_pipe # remove pipe when bg job ...
8
votes
1answer
696 views

bash process substitution with temporary file

Some programs needs their files to be seekable, for example objdump does. $ objdump -D -b binary -m i8086 <(echo 0xea 0x5b 0xe0 0x00 0xf0|xxd -r -p) objdump: Warning: '/proc/self/fd/11' is not an ...
4
votes
1answer
537 views

File descriptors and redirect in bash

Can someone explain why this command works: gpg --enable-special-filenames --verify --batch \ <(curl -s https://www.gnupg.org/ftp/gcrypt/gnupg/gnupg-2.0.29.tar.bz2.sig) \ <(curl https://www....
2
votes
3answers
658 views

Processing a single file as both input and output throughout pipes [duplicate]

Good evening, I would like to filter a file's content with some piped commands and then write the result back to the same file. I know, I can't do that the way I wrote it. Hold on … This is the ...
1
vote
1answer
657 views

Scope of variables in a process substitution

I have a command which takes two arguments. Assume we want to create both arguments by process substitution: cat <(var=123; echo $var) <(echo $var) What has to be done, to make $var available ...
2
votes
2answers
5k views

Bash - Redirect output to a variable or file descriptor, then read from the variable or file descriptor

Here's an example of a bash script that redirects all output to a file (and shows output on the screen too): # writing to it exec > >(tee --ignore-interrupts ./log) exec 2>&1 echo "here ...
2
votes
2answers
520 views

Read a password securely from within process substitution?

Related: Securely feeding a program with a password How to read from stdin in process substitution? Process substitution and cat: can't read stdin I've read the above questions and I still can't ...
5
votes
2answers
417 views

Understanding i/o redirection in the context of _process substitution_

Running GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu). I don't really understand process substitution (ProcSub) from the perspective of a user interested in lifting the hood on i/o ...
2
votes
1answer
559 views

bash while/read loop behaves differently in a mips/musl/busybox based VM

On a musl/busybox based system running in qemu (mips), the script #!/usr/bin/bash printf '%s\n' "${BASH_VERSION}" > test.txt echo 'test.txt:' cat test.txt echo "No process substitution:" while ...
4
votes
1answer
432 views

Ctrl-c kills shell when pipeline is used in input redirection subshell

If I run a command like: cat <(echo 1 | pv) | pv cat <(echo 1 | pv) | less cat <(echo 1 | pv) | cat The command seems to run forever. Entering ^C (SIGINT) kills the entire shell instead of ...
1
vote
2answers
1k views

cryptsetup: Attaching loopback device failed

I am using cryptsetup with detached header. For that I am using the --header parameter, to specify header file. I can open my device using: cryptsetup luksOpen /dev/sdb1 sdb1 --header LUKS-HEADER ...
6
votes
2answers
11k views

Running remote command with ssh getting “bash: /dev/fd/63: No such file or directory”

I have /root/test.sh on a remote server, which has the following content: #!/bin/bash date On the remote server, I get the following output: # ./test.sh Fri Dec 18 07:41:10 EST 2015 # bash <(...
1
vote
2answers
198 views

Find files and send to a temp file

Vim does support a nice option to accept a file with list of files that are then opened in a Quickfix list. Rough example, I find all files in ~ that are smaller than 1KB and pass this to Vim: find ~ ...
4
votes
1answer
1k views

How to read from stdin in process substitution? [duplicate]

I would like to send stdout to multiple commands, however I'm not sure how do I read from standard input within process substitution? My attempts: $ echo foo >(cat /dev/stdin) >(cat /dev/stdin)...
3
votes
1answer
444 views

Process substitution and cat: can't read stdin

The process substitution <(cat) doesn't work. Why? head <(cat) cat: -: Input/output error I can use an extra file descriptor, but I don't understand why the above doesn't work. # Using file ...
2
votes
2answers
323 views

Insert result of command into an executable (one command) [duplicate]

Is it possible to insert the result of a command (or even a chain of commands) into an executable in one command? Something like this: ./a.out < echo 0 Or is it necessary to do this: echo 0 > ...
7
votes
1answer
242 views

Why does OS X `install` errors on redirected input when the same version of `install` on linux works fine?

I would like to use install command in order to create a new executable file with pre-populated content (e.g. with single pwd command in it). So I've extended this example which creates a new empty ...
4
votes
2answers
877 views

Putting process substituted file descriptor into variable

I have long command roughly this: $ command-outer "long command which references a file here: filename1, and another file reference here: filename2" The files are the output of another command. So I ...
33
votes
2answers
2k views

Why does `sort <(ls -l)` work but `sort < (ls -l)` fail?

Today I'm learning something about fifo with this article: Introduction to Named Pipes, which mentions cat <(ls -l). I did some experiments by using sort < (ls -l), which pops out an error: -...
2
votes
1answer
178 views

Process substitution syntax. Forward/right bracket vs backward/left bracket

tldp lists two syntaxes for process substitution. >(command_list) and <(command_list) What is the difference, if any?
18
votes
4answers
2k views

bash: how to propagate errors in process substitution?

I want my shell scripts to fail whenever a command executed with them fails. Typically I do that with: set -e set -o pipefail (typically I add set -u also) The thing is that none of the above ...
2
votes
1answer
761 views

How to set pipe of process after process substitution in bash so that process continues after script ends?

How can I set up a process that has had its output redirected via process substitution so that it can survive after the parent script exits? I am trying to set up a Bash script to monitor the output ...
0
votes
1answer
410 views

How to catch first line of stdout from bash process substitution?

I am working with the following block of bash and it is not printing out the first line of expected output: exec 3< <(python3 -m http.server) while true; do read -t 2 line ...
2
votes
1answer
184 views

How to create dynamic process substitution based on the input (multiple FIFOs)?

I'm trying to create multiple process substitutions based on the output from the other command, however I'm not sure how I can achieve that. As sample scenario, I've given list of files: touch a.txt ...
9
votes
2answers
429 views

How bash treats “> >()”

While experimenting with output redirection and process substitution I stumbled upon the following command and its resulting output: me@elem:~$ echo foo > >(cat); echo bar bar me@elem:~$ ...
3
votes
1answer
87 views

Question about interactive detection in bash

I have a question about interactive detection in bash. The following script prints if it is called in interactive mode or not. $ cat int.sh #!/bin/bash if [ -t 0 ]; then echo "interactive" ...
8
votes
4answers
1k views

Split an input for different command and combine the result

I know how to combine the result of different command paste -t',' <(commanda) <(commandb) I know pipe same input to different command cat myfile | tee >(commanda) >(commandb) Now how ...
0
votes
2answers
251 views

process substitution for opening a list of files with an application

I wish to use process substitution to direct a list of files (produced, for example, by ls or find) to a particular application for opening/viewing. While piping such a list to xargs is suitable for a ...
7
votes
4answers
1k views

Using process substitution to trick programs expecting files, with specific extensions as argument?

Here is my use case: the command line utility melt can accept a file name, with the extension .melt on the command line, and open it; as an example, this is a proper test_p.melt file: colour:blue out=...
1
vote
1answer
546 views

“Sudo” prefixed command doesn't work; without sudo does.

I suspect this has been answered before, but I don't know what this is called, so I can't really search for it. How come this works : $ grep H=p <(udevadm info /dev/ttyUSB0) E: ID_PATH=pci-0000:...
11
votes
5answers
39k views

grep files from list

I am trying to run grep against a list of a few hundred files: $ head -n 3 <(cat files.txt) admin.php ajax/accept.php ajax/add_note.php However, even though I am grepping for a string that I know ...