help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to force delay in command execution in unamed pipe?


From: Jesse Hathaway
Subject: Re: How to force delay in command execution in unamed pipe?
Date: Mon, 4 Apr 2022 10:49:22 -0500

On Mon, Apr 4, 2022 at 10:39 AM Dennis Williamson
<dennistwilliamson@gmail.com> wrote:
> mktemp or tempile are better than hardcoding a filename.

true, updated version below:

#!/bin/bash

set -o nounset
set -o errexit
set -o pipefail
shopt -s inherit_errexit

tmp_dir=$(mktemp -p /tmp -d)

cleanup() {
    local exit_code=$?
    if [[ -d "${tmp_dir}" ]]; then
        rm -r "${tmp_dir}"
    fi
    return $exit_code
}

trap cleanup SIGINT SIGHUP SIGABRT EXIT

sync_fifo="$tmp_dir"'/sync_fifo'
mkfifo "$sync_fifo"
cat <(
    date +1-%s
    sleep 1
    echo COMPLETE >>"$sync_fifo"
) <(
    read -r _ <"$sync_fifo"
    date +2-%s
)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]