All Questions
Tagged with shell-script pipe
225 questions
3
votes
2
answers
86
views
print_one_line_and_wait_long_time | head -n1: early exit of pipe/process substitution [duplicate]
tl;dr: How to reliably ensure that the pipe a | head -n1 terminates as soon as head terminates?
Motivation: git log --grep="$MAIL_SUBJECT_LINE" --oneline --format=%H | head -n1 takes a long ...
0
votes
2
answers
86
views
Piping output to bash script
I'm going through the "sed & awk" book by Dougherty and Robbins. One of the examples calls for piping output to a shell script:
sed -f nameState list | byState
But I've found that, in ...
6
votes
1
answer
457
views
How to avoid stdout and stderr out-of-order when pipe is used?
Initially, I want to log a program (actually rsync, or diff, or others, illustrated by function prog() below) standard output, standard error, and combined output and error (namely stdall) into ...
0
votes
1
answer
75
views
Evaluating exit code of pipe or fifo
So i have something along the lines of:
set -eo pipefail
ssh localhost "ls; exit 1" | cat > output
I thought pipefail would prevent cat to write to ouput (because of the exit code from ...
2
votes
1
answer
76
views
Is there a way to `exec` a pipeline or exit shell after launching a pipeline?
I'm writing a shell wrapper script that is supposed to act as a pager (receiving input on stdin and performing output on a tty).
This wrapper prepares environment and command lines, then launches two ...
0
votes
1
answer
60
views
find with execdir, pipe redirection evaluated too early (quote issue?)
I use multiple GitHub accounts at work, so I need to modify the remote url to add my work account. I have figured out the recursive find -execdir, and how to get/sed/set the remote url, but I cannot ...
0
votes
0
answers
790
views
Understanding bash read variable substitution [duplicate]
First of all, I have little experience using Bash and I apologize for my bad English.
Maybe it's obvious.
I am trying to understand why Bash drop value of the variable in this oneliner.
echo "...
0
votes
0
answers
27
views
Bash equivalent of zsh alias at end of command (for pipes) [duplicate]
In zsh, I can set an alias at the end of a command, e.g. making G pipe through grep or L pipe through less.
Can I do something similar in bash? E.g. ls G key would expand to ls | grep key or ls L ...
9
votes
1
answer
832
views
Exit status of pipe with timeout command behaves differently in interactive shell vs shell script
Interactive sh shell session:
$ sh
$ timeout 1 yes | sed -n s/a/b/p ; echo $?
Terminated
143
$
Non-interactive script via sh -c:
$ sh -c 'timeout 1 yes | sed -n s/a/b/p ; echo $?'
0
$
Why do those ...
0
votes
2
answers
1k
views
Get exit status of the first command in a pipeline *in the second command*
My question is similar to Get exit status of process that's piped to another, but I want to get the exit status of the first command in the pipe within the pipe.
Here's an example:
false | echo &...
6
votes
1
answer
385
views
Download a file and piping to uncompress is not as fast as expected
I need to download and decompress a file as quickly as possible in a very latency sensitive environment with limited resources (A VM with 1 cpu, 2 cores, 128MB RAM)
Naturally, I tried to pipe the ...
2
votes
2
answers
1k
views
How to apply a patch as part of a pipe? In other words, how to patch stdin?
I want to apply a unified diff from mypatch.diff to stdin and output the result to stdout.
So far, I have tried:
patch -i mypatch.diff -o - -u originalfile
Which successfully applies mypatch.diff and ...
2
votes
4
answers
2k
views
How to find out if pipe is broken?
I have a POSIX shell script which has its standard output 1 redirected to a pipe. At some point of the script execution, the pipe will break and I'd like to find out (in my shell script) when that ...
1
vote
4
answers
156
views
How can I use else for `ifne`?
ifne - Run command if the standard input is not empty
If possible I want to run command if the standard input is empty as well; else section for ifne.
$ printf "hello" | ifne echo "...
0
votes
1
answer
42
views
Some dump comes out when giving inputs to program by using a pipe in Linux
I'm now trying to do exploitation by using a race condition bug.
However, a problem occurs; Values that I have never given to the process come out.
Below is a description of the case.
Scenario:
An ...