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
1 answer
19 views

ffmpeg inside while loop with find unintentionally alters iteration variable

Can someone please explain to me what is happening here? This is what I have reduced my situation down to: # make 20 test gifs out of the same source file. for i in {1..20}; do cp -p ../some-random-...
0 votes
0 answers
29 views

How to diff command outputs in vim

I tried vim -d <(ffprobe one.mp4 2>&1) <(ffprobe two.mp4 2>&1) to see the difference between the two videos' codecs etc., but vim doesn't show anything when it opens, just an empty ...
12 votes
4 answers
29k views

How to pass to ssh the key stored in a shell environment variable?

Presumably ssh tries to access the fd several times, but the fd is destroyed after it has been read the very first time: # ssh -i <(echo $KEY) [email protected] Warning: Identity file /dev/fd/11 ...
18 votes
3 answers
6k views

How to combine Bash's process substitution with HERE-document?

In Bash version 4.2.47(1)-release when I try to catenate formatted text that comes from a HERE-dcoument like so: cat <(fmt --width=10 <<FOOBAR (I want the surrounding parentheses to be part ...
0 votes
0 answers
59 views

docker build inline command fails with process substitution part

I am wondering why this docker build command fails: docker build -t inline_img -f <(cat `FROM node:12` ) . [+] Building 0.1s (2/2) FINISHED => ERROR [internal] load build definition from 11 ...
127 votes
6 answers
52k views

Process substitution and pipe

I was wondering how to understand the following: Piping the stdout of a command into the stdin of another is a powerful technique. But, what if you need to pipe the stdout of multiple commands? ...
3 votes
1 answer
179 views

Misunderstanding the purpose of a process substitution

I guess I'm missing some understanding on the use cases of a process substitution. My intuition was that a process substitution, of the form <(COMMANDS) would execute COMMANDS and then feed the ...
0 votes
1 answer
132 views

Temporary symlink in shell - "named process substitution" - rename a file without creating a copy/symlink on the disk?

Thunderbird doesn't open files that don't have .eml extension as email files, but instead starts to compose a new message and adds them as attachments. To use thunderbird in scripts I'm looking for a ...
0 votes
0 answers
91 views

Redirect output to /dev/fd/x in POSIX script, where /dev/fd/x replaces process substitution

I have a would-be POSIX script that includes filtering the stderr output: exec <cmd> "$@" 2> >(grep -v "blih bluh blah") Redirection does not occur because process ...
4 votes
1 answer
950 views

Sensitive data in process substitution

Let's say I do: #!/bin/bash content="foo" pass="secret-password" echo $content | ccrypt -f -k <(echo -n $pass) Can the permission set on the process substition /dev/fd/* ...
1 vote
1 answer
2k 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 ...
4 votes
2 answers
1k views

`tee` and `bash` process substitution order

I'd have supposed this code would have printed "oof" first: echo foo | tee >(rev) | ( sleep 1 ; cat ; ) Output: foo oof Increasing the sleep time doesn't change the order. Why doesn't that ...
1 vote
2 answers
118 views

process substitution to mimic file

I can't recall how to accomplish this, I am trying to support users to be able to include plaintext in their commands for temp usage: Here it reads from a file, file.json: lp_solve --method='simplex' -...
18 votes
4 answers
5k views

CentOS 7: What is /bin/sh? It looks like Bash but seems to be something else

When I run a Centos 7 Docker Image like this docker run -it centos:7 bash Running something which is uses Process Substitution is fine (as expected, as Bash supports Process Substitution since the ...
2 votes
1 answer
174 views

Order of fd allocation in process substitution

Inspired by this answer https://security.stackexchange.com/a/166645 I am wondering the reason behind the weird ordering when I run these commands: root@6cb8704148bf:/usr/app# echo <(printf "...
0 votes
1 answer
182 views

Named file descriptors with Process Substitution

I'm trying to use named file descriptors with Process Substitution. I wrote the following code but it doesn't work: # Open named file descriptors and associate to Process Substitution result exec {...
0 votes
0 answers
18 views

process substitution for output: syntax error depending on how script is called [duplicate]

The following script results in error when called directly, but not when called with . ./test.sh: % cat test.sh echo "foo" | tee >(rev) % . ./process_subst_test.sh foo oof % ./...
4 votes
1 answer
932 views

Why I need to type press Enter key to finish this command? [duplicate]

I'm a new Linux user and I was doing some experiments and trying to understand Process Substitution. I believe I already have a basic understanding of it. But here is a case that I don't know why. I'm ...
0 votes
0 answers
358 views

Using Process Substitution in docker as input <(command)

Recently, I faced some problems in developing bash pipelines with docker. This regards to the use of process substitution [<()] as input for a specific docker command. I know that this is a problem ...
0 votes
1 answer
109 views

Tesseract doesn't accept process substitution

I'm making a quick script that is supposed to use OCR tool (tesseract) on image in clipboard to convert it to text and output it. It looks like this: #!/bin/sh temp="$(mktemp tmpXXX.png)" ...
1 vote
0 answers
211 views

How to do shell variable expansion in process substitution? [closed]

I have a command like that in my script: regex="abba" diff <(grep "${regex}" file1) file2 The problem is if I run the script with bash script.sh the ${regex} variable doesn't ...
1 vote
1 answer
113 views

Bash script hangs when filtering stderr through sed

Introduction I have a bash script to execute a command in multiple servers through ssh. It uses GNU parallel in the parallel version, a for loop in the sequential one. The script is used like this: ...
1 vote
1 answer
364 views

bash script print stderr on failure

I am trying to make the bash script silent if everything goes fine but print out all the stderr and debug info if it crashes for some reason. Below is what I have so far. #!/usr/bin/bash set -e rm -...
0 votes
3 answers
504 views

exporting global variable in tee process substitution subshells [closed]

command | tee >(var="$(command1)") >(var1="$(command2)") echo "$var $var1" Also tried moreutils pee command | pee 'var="$(command)"' 'var1="$(...
0 votes
2 answers
461 views

Bash process substitution: how to portably refer to standard input?

The question here is the bold sentence below. Suppose I'm trying to do this: diff -u <(some command) {mystery-syntax} I am diffing the output of some command and some data that comes from standard ...
13 votes
2 answers
1k views

Bash: process substitution and stdin

The following line is obvious: echo "bla" | foo | bar But does the ones below do the same? echo "bla" | bar <(foo) echo "bla" | bar < <(foo) Which of the foo and bar read "bla" from stdin ...
0 votes
2 answers
2k views

'-sh: syntax error: unexpected "("' when attempting process substitution on an embedded Linux device with `bash`

This uses "process substitution" (<()) and a "heredoc" (cat << EOF...EOF) to open a new bash process where it runs the startup "file" (--rcfile) containing alias ...
2 votes
1 answer
370 views

How does exec > work in AWS EC2 user data?

I was writing a Terraform module for AWS EC2 that involved executing a bash in the user data section. While I was developing I had an issue in the script I wrote but neither AWS nor Terraform provided ...
5 votes
1 answer
336 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
0 answers
52 views

What does this wecho command do?

I found a script that makes a file list. The list looks like this /home/usr/example_directory /home/usr/example_directory/file1.txt /home/usr/example_directory/file2.txt /home/usr/different_directory /...
6 votes
2 answers
1k views

What is more efficient or recommended for reading output of a command into variables in Bash?

If you want to read the single line output of a system command into Bash shell variables, you have at least two options, as in the examples below: IFS=: read user x1 uid gid x2 home shell <<<...
1 vote
1 answer
209 views

Using named pipe to get process substitution exit codes

I have a script with a fairly complex command with several process substitutions and I need to get the exit codes from the commands in the process substitutions. I'm trying to do so via a named pipe ...
11 votes
4 answers
3k 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
2 answers
977 views

Pipe output from process substitution to variable

I have very complicated set of commands: command | ... | ... | tee >(grep -c '[^3]$') >(grep -c '[^35]$') 1>/dev/null I don't want to have a temporary file to save up output, as it is pretty ...
8 votes
3 answers
27k 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 <(...
60 votes
3 answers
11k 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, ...
19 votes
1 answer
4k 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 ...
18 votes
1 answer
6k views

Difference between subshells and process substitution

In bash, I want to assign my current working directory to a variable. Using a subshell, I can do this. var=$(pwd) echo $var /home/user.name If I use process substitution like so: var=<(pwd) ...
1 vote
1 answer
616 views

BusyBox tee is very slow

I am using Puppy-4.3.1 Linux on some older (Pentium 4) hardware. I am getting terrible performance out of the tee command. On this distro, tee is part of BusyBox v1.15.0. For example, this command ...
2 votes
1 answer
173 views

Using same filename for the input in sub-shell and also as output in parent shell will conflict?

Referring to this answer of mine which I used the same tmp file for the input to the process-substitution and also writing the output to the same tmp file in parent shell, does this will cause any ...
0 votes
1 answer
204 views

runit subprocess of service file not being killed on service stop

I was writing an runit service to restart picom on unlock based on this answer https://unix.stackexchange.com/a/439492/161514 #!/bin/bash OBJECT_PATH=/org/freedesktop/login1/session/$XDG_SESSION_ID ...
5 votes
4 answers
4k views

Cryptsetup: failed to attach a loop-back device

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 ...
1 vote
2 answers
288 views

Ordering output when two subshells write to stdout

I have a command of the below form input | tee >(subshell) | mainshell Both subshell and mainshell writes to stdout. So their output is not synchronised. E.g. echo "Hello\nWorld" | tee &...
4 votes
1 answer
303 views

Process substitution with Perl script

I have a Perl script which requires the following arguments: count.pl OUTPUT_FILE INPUT_FILE What I want to do is to use process substitution instead of specifying INPUT_FILE explicitly, for instance:...
6 votes
1 answer
597 views

Difference between <(commands) and >(commands) in process substitution

In process substitution I can see two syntaxes: >(command_list) and <(command_list) Often I use the second syntax. But I have no idea what is exactly the difference between the two? searching ...
31 votes
5 answers
5k 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 ...
3 votes
2 answers
698 views

Zenity Cancel button for GNU parallel progress bar

As GNU parallel's manual shows, you can use a zenity progress bar with parallel: seq 1000 | parallel -j30 --bar '(echo {};sleep 0.1)' \ 2> >(zenity --progress --auto-kill) | wc However, in ...
0 votes
1 answer
252 views

Can i use sudo in process substitution?

I want to calculate disk space via du, but I need sudo to access some dirs: $perl -ane '$i+=($F[0] =~ s/^(\d+).*/$1/r); print "$i\n"' <(sudo du /home) which gives: [sudo] password for ...
11 votes
1 answer
2k views

Wait for Bash process substitution subshells

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

1-liner process substitution for ksh

I have this command, which works fine for bash: sh <(curl -sSl https://appi.sh/launch) (launches this interactive script) I'd like to get this 1-liner working for ksh, too. Currently, it errors ...