Bug 1459253 - Bash consume exit code when keword "local" is used.
Summary: Bash consume exit code when keword "local" is used.
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: bash
Version: 5.11
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: rc
: ---
Assignee: Siteshwar Vashisht
QA Contact: BaseOS QE - Apps
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-06-06 16:01 UTC by Jakub Prokeš
Modified: 2017-06-13 02:36 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-06-13 02:36:33 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
Reproducer (267 bytes, application/x-shellscript)
2017-06-06 16:01 UTC, Jakub Prokeš
no flags Details

Description Jakub Prokeš 2017-06-06 16:01:34 UTC
Created attachment 1285465 [details]
Reproducer

Description of problem:

x=$(echo 33; exit 33)
returns exit code 33, but
local x=$(echo 33; exit 33)
returns 0


Version-Release number of selected component (if applicable):
bash-4.3.43-4.fc25.x86_64
4.3.43(1)-release

How reproducible:
reproducer attached

Actual results:
bash-4.3.43-4.fc25.x86_64
GNU bash, version 4.3.43(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
f1: 0
x=
f2: 33
x=33
Invalid


Expected results:
f1 and f2 produce same output

Additional info:

Comment 1 Siteshwar Vashisht 2017-06-09 11:52:05 UTC
Do you wish to report this bug for RHEL 5 or Fedora ? I see that you are running Fedora packages on your system. Also, is there something missing from your reproducer steps ? local keyword can be used only within functions. Please provide a full reproducer.

Comment 2 Kamil Dudka 2017-06-09 21:25:17 UTC
(In reply to Jakub Prokeš from comment #0)
> local x=$(echo 33; exit 33)

This is a known programming mistake in your code, not a bug in the interpreter:

https://github.com/koalaman/shellcheck/wiki/SC2155


Note You need to log in before you can comment on or make changes to this bug.