process-substitution

Get exit code of process substitution with pipe into while loop

泪湿孤枕 提交于 2019-11-27 18:01:38
问题 The following script calls another program reading its output in a while loop (see Bash - How to pipe input to while loop and preserve variables after loop ends): while read -r col0 col1; do # [...] done < <(other_program [args ...]) How can I check for the exit code of other_program to see if the loop was executed properly? 回答1: Note: ls -d / /nosuch is used as an example command below, because it fails (exit code 1 ) while still producing stdout output ( / ) (in addition to stderr output).

Bash script process substitution Syntax error: “(” unexpected

别说谁变了你拦得住时间么 提交于 2019-11-27 05:39:46
I want to run this script: #!/bin/bash echo <(true) I run it as: sh file.sh And I get " Syntax error: "(" unexpected " . I found some similar situations but still can't solve this. I'm a beginner at shell scripting , but as I understand: the shebang I use is correct and chooses the bash shell , so the process substitution syntax should work I try the same from the command line and it works. I checked with echo $0 and it gives me " bash " , so what's the difference from running the command in the command line and from a script that invokes the same shell? Maybe it's something simple, but I

Bash process substitution and syncing

£可爱£侵袭症+ 提交于 2019-11-27 02:16:40
问题 (Possibly related to Do some programs not accept process substitution for input files?) In some Bash unit test scripts I'm using the following trick to log and display stdout and stderr of a command: command > >(tee "${stdoutF}") 2> >(tee "${stderrF}" >&2) This process produces some output to stdout, so the $stdoutF file gets some data. Then I run another command which does not output any data: diff -r "$source" "$target" > >(tee "${stdoutF}") 2> >(tee "${stderrF}" >&2) However, it doesn't

Why source command doesn't work with process substitution in bash 3.2?

只谈情不闲聊 提交于 2019-11-26 19:08:58
I've the following shell script: cat <(echo foo) source <(echo bar=bar) echo $bar However it works differently in GNU bash 3.2 and 4.3 as shown below: $ /bin/bash foo.sh foo 3.2.53(1)-release $ /usr/local/bin/bash foo.sh foo bar 4.3.33(1)-release Why this works only on one version? Is it a bug or added feature? It seems the process substitution works fine, however problem lay when sourcing the file. If this is expected behaviour, what other syntax should I use instead to source something from the standard input to be compatible between different bash versions? This is a known limitation in

Capture stdout to a variable but still display it in the console

廉价感情. 提交于 2019-11-26 15:17:58
I have a bash script which calls several long-running processes. I want to capture the output of those calls into variables for processing reasons. However, because these are long running processes, I would like the output of the rsync calls to be displayed in the console in real-time and not after the fact. To this end, I have found a way of doing it but it relies on outputting the text to /dev/stderr. I feel that outputting to /dev/stderr is not a good way of doing things. VAR1=$(for i in {1..5}; do sleep 1; echo $i; done | tee /dev/stderr) VAR2=$(rsync -r -t --out-format='%n%L' --delete -s

Why source command doesn&#39;t work with process substitution in bash 3.2?

微笑、不失礼 提交于 2019-11-26 06:07:52
问题 I\'ve the following shell script: cat <(echo foo) source <(echo bar=bar) echo $bar However it works differently in GNU bash 3.2 and 4.3 as shown below: $ /bin/bash foo.sh foo 3.2.53(1)-release $ /usr/local/bin/bash foo.sh foo bar 4.3.33(1)-release Why this works only on one version? Is it a bug or added feature? It seems the process substitution works fine, however problem lay when sourcing the file. If this is expected behaviour, what other syntax should I use instead to source something