Bug 1125351 - bash should default to error out on undefined variables
Summary: bash should default to error out on undefined variables
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: bash
Version: 7.2
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: rc
: ---
Assignee: Ondrej Oprala
QA Contact: BaseOS QE - Apps
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-07-31 15:57 UTC by Dave Sullivan
Modified: 2016-02-01 02:09 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2014-08-04 05:24:59 UTC


Attachments (Terms of Use)

Description Dave Sullivan 2014-07-31 15:57:13 UTC
Description of problem:

Good practice for bash script should use set -o

Which will allow bash to exit on run with an undefined variable.

This protects against bad mistakes 

e.g. if FOO is not defined and set -o is not used the following can cause a very bad situation

rm -rf /${FOO} 

So why not have bash default environment run as set -o


Version-Release number of selected component (if applicable):

current bash

How reproducible:


Steps to Reproduce:
1.
2.
3.

Actual results:


Expected results:


Additional info:

Comment 2 Dave Sullivan 2014-07-31 16:19:00 UTC
[root@seaking Documentation]# cat test.bash 
#!/bin/bash

set -o nounset

echo $FOO
[root@seaking Documentation]# bash test.bash 
test.bash: line 5: FOO: unbound variable

Comment 3 Ondrej Oprala 2014-08-04 05:24:59 UTC
I could not possibly force this to everyone as a default behaviour.
Just think of all the scripts that use something like this:

       install -p some_binary $PREFIX/bin


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