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
59 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 ...
3
votes
2answers
181 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
1answer
39 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 ...
2
votes
1answer
75 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 ...
3
votes
1answer
64 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 ...
0
votes
1answer
77 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 ...
6
votes
1answer
530 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:...
-1
votes
1answer
36 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" ...
2
votes
1answer
42 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 (...
-1
votes
4answers
93 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-...
0
votes
1answer
84 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: ...
0
votes
1answer
90 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 ...
0
votes
0answers
48 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>&...
0
votes
1answer
38 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 ...
3
votes
3answers
148 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 ...
1
vote
1answer
388 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 "{...
1
vote
1answer
59 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 ...
4
votes
2answers
892 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 ...
0
votes
0answers
70 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 ...
0
votes
1answer
77 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 ...
1
vote
0answers
34 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 ...
3
votes
2answers
121 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 < <(...
0
votes
0answers
54 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 &&...
5
votes
0answers
52 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=$(<...
11
votes
2answers
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 ...
7
votes
3answers
389 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. ...
0
votes
1answer
131 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 ...
0
votes
0answers
180 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 ...
0
votes
1answer
156 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 ...
1
vote
1answer
2k 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 ...
6
votes
2answers
526 views

Process substitution and redirection using tee

Suppose that you redirect, in bash, the standard output of a command cmd to a file named f.out, and the standard error to f.err, using tee to preserve console printing: cmd 1> >(tee f.out) 2>...
2
votes
1answer
237 views

concurrent processing in bash using process expansion, and redirection

Apart from possible races that have to be controlled by using proper synchronisation, it's possible in bash to feed a data source concurrently into multiple pipelines and collect all their outputs ...
4
votes
1answer
1k views

Process substitution inside a subshell to set a variable

I'm trying to run a script remotely and use its standard output to populate a variable. I'm doing this to avoid temporary files. Here's the pattern I'm trying: var=$(bash <(curl -fsSkL http://...
2
votes
1answer
225 views

How to use bash process substitution for a sftp private key file?

With my team, we need to share a few private keys and we store them in a pass repository. So instead of extracting the key and storing it in cleartext on the filesystem, I am looking for a way to ...
5
votes
1answer
637 views

Why is the stdout of a `>()` subshell different if it's part of a redirection (e.g. `> >()`)?

This is a followup question to: Why does `... | sed 's/^/stdout: /'` print on empty stdin when `... > >(sed 's/^/stdout: /')` doesn't? To be more concrete, why is this a ...
3
votes
4answers
1k views

Why does `… | sed 's/^/stdout: /'` print on empty stdin when `… > >(sed 's/^/stdout: /')` doesn't?

I'm trying to understand what causes the difference in these 2 constructs that I thought were functionally equivalent: $ ( echo foo >&2 ) 2> >(sed 's/^/stderr: /') | sed 's/^/stdout: /' ...
0
votes
1answer
72 views

Confused why script does not exit

I have this script verbatim: #!/usr/bin/env bash handle_json(){ while read line; do cat <<EOF {"@json-stdio":true,"value":{"mark":"$1","v":"$line"}} EOF done; } ( echo; echo; echo '...
0
votes
1answer
158 views

Is this bash argument substitution?

While studying bash process substitution, I found this: counter=0 while IFS= read -rN1 _; do ((counter++)) done < <(find /etc -printf ' ') echo "$counter files" If I understand correctly,...
-4
votes
2answers
146 views

Does process substitution need to be double quoted?

Double quoting command substitution is a good practice. Is it the same for process substitution (<() and >())? It seems double quotes allow command substitution, but disallow process ...
1
vote
0answers
160 views

Using a here-doc with trailing backslashes inside a process substitution in bash

This: cat <<EOF one two three EOF Prints: one two three And this: cat <<EOF one \\ two \\ three EOF Prints: one \ two \ three But while this: cat <( cat <<EOF one two ...
5
votes
1answer
122 views

Specifying the file extension produced by zsh process substitution

I want to use zsh's process substitution to create a temporary file that can then be read by another program. However, the file it generates has no file extension, so the program reading it refuses to ...
3
votes
3answers
370 views

Pass input to multiple commands and compare their outputs

I am trying to pass standard input into multiple commands and compare their outputs. My current attempt seems close, but doesn't quite work - plus it relies on temporary files which I feel would not ...
2
votes
0answers
61 views

Command requires file, avoid creating temporary file [duplicate]

<() doesn't seem to do what I expect. This command requires a text file (it's JLinkExe, the text file contains commands for JLinkExe to run. But that shouldn't matter). JLinkExe -CommanderScript &...
0
votes
0answers
40 views

Process substitution of commands on separate lines of a string

I have a variable, COMMANDS, that contains a list of newline-separated commands (I know for example in this case that there will never be newlines, but they could be separated by NUL). For example, ...
-1
votes
4answers
828 views

simple cat echo process substitution hangs

Simple process substitution with cat seems to hang: cat >( echo hello; ) never finishes. Also tried: cat >( echo hello; exit; ) Manually closing the standard out file descript from the ...
0
votes
1answer
807 views

multiple pipes in loop, saving pipeline-result to array

I am trying to do the following (using bash): Search for files that always have the same name and extract data from these files. I want to store the extracted data in new arrays I am almost there, I ...
1
vote
2answers
70 views

How to create sh compatible bash function

I have this bash function: zmx(){ "$@" \ 2> >( while read line; do echo -e "r2g: $line"; done ) \ 1> >( while read line; do echo -e "r2g: $line"; done ) } this function is ...
0
votes
2answers
118 views

Which signal >(process) receives after main shell exits?

This is a Zshell question, although Bash, if it has >(command) syntax (i.e. process substitution of such kind), can hint a solution too. This really basic code explains all: % fun() { setopt ...
0
votes
1answer
380 views

Using process substitution, only send stderr to process

I have this: exec > >( while read line; do echo " stdout: $line"; done ) exec 2> >( while read line; do echo " stderr: $line"; done ) echo "rolo" >&2 echo "cholo" if you run that ...
1
vote
1answer
583 views

Why process substitution is faster than pipe in this case? [duplicate]

I am wondering why ls -1 | while read file; do echo $file; tail -n 100 $file > >(sleep 1 && cat > $file) done is faster than ls -1 | while read file; do echo $...