Skip to main content

All Questions

Tagged with
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 ...
teapot's user avatar
  • 361
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 ...
Mike's user avatar
  • 103
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 ...
midnite's user avatar
  • 593
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 ...
PKSWE's user avatar
  • 103
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 ...
intelfx's user avatar
  • 5,659
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 ...
Robert Altman's user avatar
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 "...
bas1c's user avatar
  • 1
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 ...
SRobertJames's user avatar
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 ...
finefoot's user avatar
  • 3,504
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 &...
MilkyDeveloper's user avatar
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 ...
Richard's user avatar
  • 113
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 ...
finefoot's user avatar
  • 3,504
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 ...
finefoot's user avatar
  • 3,504
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 "...
alper's user avatar
  • 507
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 ...
toubva's user avatar
  • 1

15 30 50 per page
1
2 3 4 5
15