process-substitution

Bash script process substitution Syntax error: “(” unexpected

99封情书 提交于 2019-12-28 02:19:05
问题 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

Syntax error in shell script with process substitution

别来无恙 提交于 2019-12-17 05:12:24
问题 I have this shell script which I use to back up my system. There is a line: tar -Pzcpf /backups/backup.tar.gz --directory=/ --exclude=proc --exclude=sys --exclude=dev/pts --exclude=backups --exclude=var/log / 2> >(grep -v 'socket ignored' >&2) As you can see, I have been trying to filter out the annoying, useless "socket ignored" error by tar, using this blog post. What I get from shell upon execution is: /bin/sysback: line 45: syntax error near unexpected token >' /bin/sysback: line 45: tar

Syntax error in shell script with process substitution

空扰寡人 提交于 2019-12-17 05:12:08
问题 I have this shell script which I use to back up my system. There is a line: tar -Pzcpf /backups/backup.tar.gz --directory=/ --exclude=proc --exclude=sys --exclude=dev/pts --exclude=backups --exclude=var/log / 2> >(grep -v 'socket ignored' >&2) As you can see, I have been trying to filter out the annoying, useless "socket ignored" error by tar, using this blog post. What I get from shell upon execution is: /bin/sysback: line 45: syntax error near unexpected token >' /bin/sysback: line 45: tar

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

那年仲夏 提交于 2019-12-17 03:02:42
问题 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

Process Substitution For Each Array Entry, Without Eval

心已入冬 提交于 2019-12-12 14:09:24
问题 I have an array of arbitrary strings, for instance a=(1st "2nd string" $'3rd\nstring\n' ...) . I want to pass these strings to a command that interprets its arguments as files, for instance paste . For a fixed number of variables, we could use process substitution paste <(printf %s "$var1") <(printf %s "$var2") <(printf %s "$var3") but that does only work if the number of variables is known beforehand. For the array a , we could write something fairly safe like eval paste $(printf '<(printf %

Tee with process substitution misunderstanding

不打扰是莪最后的温柔 提交于 2019-12-11 05:12:53
问题 I am trying to write a pretty printer for LDAP entries which only fetches the root LDAP record once and then pipes the output into tee that invokes the pretty printer for each section. For illustration's sake, say my group_entry function returns the LDIF of a specific LDAP DN. The details of which aren't important, so let's say it always returns: dn: cn=foo,dc=example,dc=com cn: foo owner: uid=foo,dc=example,dc=com owner: uid=bar,dc=example,dc=com member: uid=foo,dc=example,dc=com member: uid

Exit tail upon string detection

为君一笑 提交于 2019-12-11 03:06:41
问题 I'm writing a barrier to stop to hold the execution of a script until a certain keyword is logged. The script is pretty simple: tail -F -n0 logfile.log | while read LINE; do [[ "$LINE" == *'STOP'* ]] && echo ${LINE} && break; done or tail -F -n0 logfile.log | grep -m1 STOP Still, despite printing STOP as soon as it is detected, these chunks of code terminate only after the following line is written . I.e: printf "foo\n" >> logfile.log # keeps reading printf "foo\n" >> logfile.log # keeps

How can I use read timeouts with stat?

孤人 提交于 2019-12-10 11:56:33
问题 I have the following code: #!/bin/bash read -t1 < <(stat -t "/my/mountpoint") if [ $? -eq 1 ]; then echo NFS mount stale. Removing... umount -f -l /my/mountpoint fi How do I mute the output of stat while at the same time being still able to detect its error level in the subsequent test? Adding >/dev/null 2>&1 inside the subshell, or in the end of the read line does not work. But there must be a way... Thanks for any insights on this! 回答1: Use Command-Subsitution, Not Process Substitution

Understanding exec in bash

风格不统一 提交于 2019-12-10 10:45:21
问题 After reading explanations of how the exec builtin works in bash, I understand that its basic function is to replace the current process without forking. It also seems to be used for redirecting I/O and closing file descriptors in the current process, which confuses me. Is this some unrelated additional thing exec does? Can it be understood in the context of "replacing the current process"? And how does this work when combined with process substitution, e.g. exec 3< <(my program) ? 回答1: Here

Bash setting a global variable inside a loop and retaining its value — Or process substituion for dummies

梦想的初衷 提交于 2019-12-09 12:01:32
问题 I'm a C/C++ programmer and quite stupid in general (or at least the way bash does things it makes me feel confused). I can't wrap my head around process substitution. I need to define a global boolean, set it somewhere in a loop, and make use of it in global scope. Could someone please explain in the simplest way possible how to adapt the code below to allow me to achieve my use case, simple enough so that I don't have to contort my brain again tomorrow to try and grasp process substitution .