Skip to main content
added 18 characters in body
Source Link
Petr Skocik
  • 29.7k
  • 18
  • 90
  • 154
 deployArgs=`build | tee /dev/tty  | extractDeployArgs` &&
    deploy "$deployArgs" #won't run unless extractDeployArgs suceeded

tee /dev/tty will print directly to the terminal and pass the output to the next command in the pipeline at the same time.

Feel(Feel free to replace it with some other file (or /dev/fd/"$someFileDescriptor" if you need want the side output to go to $someFileDescriptor).)

In more advanced shells (ksh, bash, zsh, but not in dash) you can set -o pipefail to make sure the pipeline fails if any of its links fails (useful if extractDeployArgs can't tell from its input whether build suceeded or not).

 deployArgs=`build | tee /dev/tty  | extractDeployArgs` &&
    deploy "$deployArgs" #won't run unless extractDeployArgs suceeded

tee /dev/tty will print directly to the terminal and pass the output to the next command in the pipeline at the same time.

Feel free to replace it with some other file (or /dev/fd/"$someFileDescriptor" if you need want the side output to go to $someFileDescriptor).

In more advanced shells (ksh, bash, zsh) you can set -o pipefail to make sure the pipeline fails if any of its links fails (useful if extractDeployArgs can't tell from its input whether build suceeded or not).

 deployArgs=`build | tee /dev/tty  | extractDeployArgs` &&
    deploy "$deployArgs" #won't run unless extractDeployArgs suceeded

tee /dev/tty will print directly to the terminal and pass the output to the next command in the pipeline at the same time.

(Feel free to replace it with some other file (or /dev/fd/"$someFileDescriptor" if you need want the side output to go to $someFileDescriptor))

In more advanced shells (ksh, bash, zsh, but not in dash) you can set -o pipefail to make sure the pipeline fails if any of its links fails (useful if extractDeployArgs can't tell from its input whether build suceeded or not).

added 208 characters in body
Source Link
Petr Skocik
  • 29.7k
  • 18
  • 90
  • 154
(
set -o pipefail
builddeployArgs=`build | tee /dev/tty  | extractStuffextractDeployArgs` |&&
 xargs   deploy
) "$deployArgs" #won't run unless extractDeployArgs suceeded

set -otee pipefail/dev/tty causes a pipelinewill print directly to fail if any of its subcommands failsthe terminal and pass the output to the next command in the pipeline at the same time.

Feel free to replace it with some other file (or tee /dev/ttyfd/"$someFileDescriptor" causesif you need want the passingside output to show on the terminal. go to xargs$someFileDescriptor takes stdin and puts and places it in the argument array of its argument command).

In more advanced shells (()ksh creates a subshell so the, bash, zsh) you can set -eoo pipefail setting is undone as soon asto make sure the subshell exitspipeline fails if any of its links fails (useful if extractDeployArgs can't tell from its input whether build suceeded or not).

(
set -o pipefail
build | tee /dev/tty  | extractStuff | xargs deploy
)

set -o pipefail causes a pipeline to fail if any of its subcommands fails.

tee /dev/tty causes the passing output to show on the terminal. xargs takes stdin and puts and places it in the argument array of its argument command.

() creates a subshell so the set -eo pipefail setting is undone as soon as the subshell exits.

 deployArgs=`build | tee /dev/tty  | extractDeployArgs` &&
    deploy "$deployArgs" #won't run unless extractDeployArgs suceeded

tee /dev/tty will print directly to the terminal and pass the output to the next command in the pipeline at the same time.

Feel free to replace it with some other file (or /dev/fd/"$someFileDescriptor" if you need want the side output to go to $someFileDescriptor).

In more advanced shells (ksh, bash, zsh) you can set -o pipefail to make sure the pipeline fails if any of its links fails (useful if extractDeployArgs can't tell from its input whether build suceeded or not).

Source Link
Petr Skocik
  • 29.7k
  • 18
  • 90
  • 154

(
set -o pipefail
build | tee /dev/tty  | extractStuff | xargs deploy
)

set -o pipefail causes a pipeline to fail if any of its subcommands fails.

tee /dev/tty causes the passing output to show on the terminal. xargs takes stdin and puts and places it in the argument array of its argument command.

() creates a subshell so the set -eo pipefail setting is undone as soon as the subshell exits.