Skip to content

avoid pipefail issue with create_passwd #882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

simonLeary42
Copy link

@simonLeary42 simonLeary42 commented May 15, 2025

if you want to use bash "strict mode" in a batch connect job, you might be confused when your job fails.

#!/bin/bash
set -euo pipefail
set -x
password="$(generate_passwd)
echo "hello, world!"

output.log:

++ tr -cd '[:alnum:]'
++ head -c16
+ password=IhZj0VloAJ4r0FwN

create_passwd successfully creates a password, but since head closes its stdin while tr is still trying to write into it, tr gets a SIGPIPE and proces a return code = 128 + SIGPIPE = 141. set -o pipefail means that the first nonzero exit code of any process in the pipeline is used for the whole pipeline, and set -e means that execution stops after the 1st nonzero exit code.

To prevent this, make sure that pipefail is disabled for create_passwd. To avoid changing the option in the original shell, check_passwd runs in a subshell (() instead of {}). subshell behavior tested:

$ set -o pipefail; set -o | grep pipefail; (set +o pipefail; set -o | grep pipefail); set -o | grep pipefail
pipefail       	on
pipefail       	off
pipefail       	on

@johrstrom
Copy link
Contributor

OK I'll have to test this a bit because I'm not really a bash/shell expert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants