ydb icon indicating copy to clipboard operation
ydb copied to clipboard

Do not modify SHELLOPTS env var

Open maximyurchuk opened this issue 10 months ago • 3 comments

Changelog entry

Setting SHELLOPTS environment variable lead to unconditional inheritance of shell options.

Github action set this variable, do set -e and that situation lead that all shell invocations from tests inherit set -e by default, but tests expect the default behaviour without set -e.

Changelog category

  • Bugfix
  • Not for changelog (changelog entry is not required)

Additional information

Minimal example:

Consider the following scripts

maxim-yurchuk@maxim-yurchuk-vm:/tmp/shellopts$ cat first.sh 
#!/usr/bin/env bash
set -e

echo "Before second.sh invocation" 
./second.sh
echo "After second.sh invocation" 

maxim-yurchuk@maxim-yurchuk-vm:/tmp/shellopts$ cat second.sh 
#!/usr/bin/env bash

echo "Before fail invocation" 
./non_existing
echo "After fail invocation"

In the default environment output of first.sh is following:

maxim-yurchuk@maxim-yurchuk-vm:/tmp/shellopts$ ./first.sh 
Before second.sh invocation
Before fail invocation
./second.sh: line 4: ./non_existing: No such file or directory
After fail invocation
After second.sh invocation

i.e. set -e was not inherited by second.sh

But if someone creates environment variable SHELLOPTS behaviour is changed:

maxim-yurchuk@maxim-yurchuk-vm:/tmp/shellopts$ export SHELLOPTS
maxim-yurchuk@maxim-yurchuk-vm:/tmp/shellopts$ ./first.sh 
Before second.sh invocation
Before fail invocation
./second.sh: line 4: ./non_existing: No such file or directory

I.e. second.sh got set -e implicitly. This behaviour is strongly unexpected.

So I've just remove setting of SHELLOPTS.

maximyurchuk avatar Apr 27 '24 08:04 maximyurchuk

:white_circle: 2024-04-27 08:07:56 UTC Pre-commit check for 5992a45eb90d57825fcd02cede148314013eef8a has started. :white_circle: 2024-04-27 08:07:59 UTC Build linux-x86_64-release-clang14 is running... :green_circle: 2024-04-27 08:09:07 UTC Build successful.

github-actions[bot] avatar Apr 27 '24 08:04 github-actions[bot]

:white_circle: 2024-04-27 08:10:17 UTC Pre-commit check for 5992a45eb90d57825fcd02cede148314013eef8a has started. :white_circle: 2024-04-27 08:10:19 UTC Build linux-x86_64-relwithdebinfo is running... :green_circle: 2024-04-27 08:11:24 UTC Build successful. :white_circle: 2024-04-27 08:12:47 UTC Tests are running... :red_circle: 2024-04-27 08:12:53 UTC Test run completed, no test results found for commit 710308c386ce5173b4cf4d56e7fd40520d503a6b. Please check build logs.

github-actions[bot] avatar Apr 27 '24 08:04 github-actions[bot]

:white_circle: 2024-04-27 08:10:17 UTC Pre-commit check for 5992a45eb90d57825fcd02cede148314013eef8a has started. :white_circle: 2024-04-27 08:10:19 UTC Build linux-x86_64-release-asan is running... :green_circle: 2024-04-27 08:11:25 UTC Build successful. :white_circle: 2024-04-27 08:12:47 UTC Tests are running... :red_circle: 2024-04-27 08:12:53 UTC Test run completed, no test results found for commit 710308c386ce5173b4cf4d56e7fd40520d503a6b. Please check build logs.

github-actions[bot] avatar Apr 27 '24 08:04 github-actions[bot]