2022 Developer Survey is open! Take survey.

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
4 votes
1 answer
173 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 ...
user avatar
0 votes
0 answers
32 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 ...
user avatar
0 votes
1 answer
28 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)" ...
user avatar
1 vote
0 answers
49 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 ...
user avatar
  • 21
1 vote
1 answer
34 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: ...
user avatar
1 vote
1 answer
62 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 -...
user avatar
  • 4,039
-1 votes
3 answers
86 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="$(...
user avatar
0 votes
2 answers
94 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 ...
user avatar
  • 6,656
0 votes
2 answers
97 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 ...
user avatar
2 votes
1 answer
181 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 ...
user avatar
17 votes
4 answers
3k 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 ...
user avatar
  • 1,732
0 votes
0 answers
40 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 /...
user avatar
  • 23
6 votes
2 answers
837 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 <<<...
user avatar
  • 478
1 vote
1 answer
77 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 ...
user avatar
  • 2,087
0 votes
2 answers
224 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 ...
user avatar
1 vote
1 answer
271 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 ...
user avatar
  • 215
2 votes
1 answer
100 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 ...
user avatar
  • 38.2k
0 votes
1 answer
62 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 ...
user avatar
1 vote
2 answers
133 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 &...
user avatar
  • 4,039
4 votes
1 answer
157 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:...
user avatar
  • 343
2 votes
1 answer
159 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 ...
user avatar
3 votes
2 answers
441 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 ...
user avatar
0 votes
1 answer
149 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 ...
user avatar
2 votes
1 answer
264 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 ...
user avatar
  • 1,987
3 votes
1 answer
213 views

Why is ssh-add <(echo 'pk contents') not working?

I am getting this error: Permissions 0660 for '/dev/fd/63' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. when I run ...
user avatar
0 votes
1 answer
348 views

how to keep stty sane after piping strace to vim?

this makes vim madness: $strace -o >(vim -; stty sane) file.out; stty sane I have typed stty sane in processed substitution as well as in next command but none of them did their job. Once i piped ...
user avatar
  • 260
6 votes
1 answer
661 views

Script not working when passed to bash via -c

Why does this work: $ cat test.sh #!/bin/bash cat <(date|awk '{print $1}') $ ./test.sh Thu but not as a command passed to bash: $ bash -c "cat <(date|awk '{print $1}')" Thu 2 Apr 2020 12:52:...
user avatar
-1 votes
1 answer
50 views

Environment variables are not set when redirect echo through a pipeline at a function [closed]

This command: echo '18' | source meta-cmf-raspberrypi/setup-environment Not set the environment variables as instead happened with a simply: source meta-cmf-raspberrypi/setup-environment With "18" ...
user avatar
2 votes
1 answer
54 views

Can't run file(1) on output of file descriptor, pipe, fifo, device, etc

I want to run the file(1) command on the output of another command, but all I get is $ file -sL <(echo \#include \<stdio.h\>) /dev/fd/63: ERROR: (null) This works as expected in file-5.04 (...
user avatar
-1 votes
4 answers
284 views

What is the difference between a heredoc and process substitution?

In this answer, it is explained how to use a heredoc to interact with interactive programs by connecting their stdin with a heredoc. https://stackoverflow.com/questions/21130757/send-commands-to-...
user avatar
0 votes
1 answer
362 views

How to pass a subprocess to a command with bash

I'm trying to pass multiple outputs to a command using sub-processes. This is (a shortened version of) my command: cat "$1" one=cat "$1" The output of command <(echo "foo") is foo /dev/fd/63: ...
user avatar
1 vote
2 answers
1k views

Trying to run .sh script from curl

I am having trouble running a shell script. So for context, I am using bash <(curl -s -L https://test.com/detect.sh) --argument1=true When I run this command in my Ubuntu environment, it works ...
user avatar
  • 111
0 votes
0 answers
133 views

Bash complex redirection (what does this command do)?

I recently was messing with an AWS virtual machine setup script. The documentation says to include this line: exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&...
user avatar
0 votes
1 answer
84 views

Executing commands from process substitution in xinitrc

I felt that an .xinitrc like this #!/bin/sh bash <(sed -n 'H /^exec ./{ x s/\([^\n]\+ &\n\)*exec .*// p }' /etc/X11/xinit/xinitrc) xmonad & # ... exec xterm where ...
user avatar
  • 2,933
3 votes
3 answers
508 views

bash: race condition with pipeline, tee and process substitution

I want to see twice being output twice, but this script will only output it once: dump() { (sleep 1; cat) > "$1" } (sleep 0; echo "twice") | tee >(dump "./a.txt") echo "$(< "a.txt")" To ...
user avatar
  • 3,754
3 votes
1 answer
1k views

paste: /dev/fd/63: No such file or directory

I'm new to Unix command. I was trying to execute the following commands in Git Bash and it directs to error message: paste: /dev/fd/63: No such file or directory # Set Up Image Lists paste <(awk "{...
user avatar
  • 31
1 vote
1 answer
98 views

Why does dd dislike taking input from process substitution?

Is there something about process substitution (which I think is implemented with unnamed pipes) that is incompatible with dd? For example, this fails: $ dd if=<(unzip -p raspbian.zip) of=/dev/sdb ...
user avatar
  • 359
5 votes
2 answers
4k views

Run asynchronous tasks and retrieve their exit code and output in bash

I have to run a bunch of bash commands asynchronously and as soon as one finishes, I need to perform actions according to its exit code and output. Note that I can't predict how for long any of these ...
user avatar
0 votes
0 answers
90 views

bash: how to pass variables to a loop within a process substitution

How do you pass variable values within a process substitution to a loop within that process substitution? I'm reading a csv file into an associative array, and while reading each line, I would like ...
user avatar
  • 1
0 votes
1 answer
757 views

zsh: inconsistent error handling in assignments

This is zsh -f: Fereidoons-MacBook-Pro% local a=$(jaja) && echo bad zsh: command not found: jaja bad Fereidoons-MacBook-Pro% a=$(jaja) && echo bad zsh: command not found: jaja ...
user avatar
  • 1,287
1 vote
0 answers
54 views

How to use diff3 with text arguments instead of file paths?

I want to use diff3 with text arguments instead of file paths. For example, diff3 some_files/mine.txt some_files/older.txt ~/Downloads/yours.txt works as expected. However, I've been trying to achieve ...
user avatar
4 votes
2 answers
205 views

Process Substitution in Bash

Can someone explain to me why I don't see the output of "date" from the below command? For N number for STDIN inputs, it's printing only for last (N-1) commands? [root@RAJ-RHEL6 raj]# cat < <(...
user avatar
  • 43
0 votes
0 answers
89 views

Process substitution doesn't work with diff and node

I'm trying to compare the output of my fizzbuzz.js program: for (let i = 1; i <= 100; i++) { let out = ""; if (i % 3 == 0) out += "Fizz"; if (i % 5 == 0) out += "Buzz"; if (i % 3 &&...
user avatar
  • 425
5 votes
0 answers
63 views

cat in process substitution hangs: what is it waiting for? [duplicate]

I have this piece of code using Process Substitution. When I run it, it works fine, but it does not exit - just hangs there waiting for input. Why and how to overcome? prepro() { in=$(<...
user avatar
  • 407
11 votes
2 answers
1k views

Why do I seem to lose data using this bash pipe construction?

I am trying to combine a few programs like so (please ignore any extra includes, this is heavy work-in-progress): pv -q -l -L 1 < input.csv | ./repeat <(nc "host" 1234) Where the source of ...
user avatar
7 votes
3 answers
1k views

Can I duplicate output of a pipe?

Well, the task is simple: a part of my script has to compute both md5 and sha1 hashes. The input is a file - big file - and hashes have to be put into MD and SH variables for later output composition. ...
user avatar
  • 918
0 votes
1 answer
482 views

Process substitution to script in order to monitor iotop

I am actively trying to get the output of the iotop for monitoring. As you know, the iotop is interactive, meaning that once started, it'll provide live updates on disk usage on the system. I'm ...
user avatar
2 votes
0 answers
357 views

Write stdout to a temp file using command line

Say for example we wanted to write the env from the host to Docker container, one way would be to use a temp file: env > env_file && docker run --env-file env_file image_name to avoid a ...
user avatar
0 votes
1 answer
330 views

How to send stdin to while loop using redirection operator

Not sure if I used the right words in the title, I am trying to do this: while read line; do echo "$line" exit; done; <( echo "foo\n"; exit ) but it hangs, I don't think the while loop ...
user avatar
6 votes
3 answers
12k 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) user@example.com Warning: Identity file /dev/fd/11 ...
user avatar
  • 2,034