[dim PATCH 1/2] dim: add -s option to treat unset variables as an error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use -s for "strict" to 'set -u'. Fix the variable references to not fail
before subcommand call. The goal is to unconditionally 'set -u' at the
top, but it can't be done in one go, so add a way to test drive first.

Signed-off-by: Jani Nikula <jani.nikula@xxxxxxxxx>
---
 dim | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/dim b/dim
index 99120b82513e..3e10f360d482 100755
--- a/dim
+++ b/dim
@@ -145,7 +145,7 @@ function pause
 	echo
 }
 
-while getopts hdfi opt; do
+while getopts hdfis opt; do
 	case "$opt" in
 		d)
 			DRY_RUN=--dry-run
@@ -160,6 +160,11 @@ while getopts hdfi opt; do
 		h)
 			HELP=1
 			;;
+		s)
+			# FIXME: transitional, do unconditionally at the top
+			# when there are no more errors about unbound variables
+			set -u
+			;;
 		*)
 			echoerr "See '$dim help' for more information."
 			exit
@@ -180,7 +185,7 @@ fi
 #
 
 # Make sure we use 'dim_foo' within dim instead of 'dim foo'.
-if [[ -n "$__dim_running" ]]; then
+if [[ -n "${__dim_running:-}" ]]; then
 	echoerr "INTERNAL ERROR: do not recurse back to dim"
 	exit 1
 fi
@@ -1829,7 +1834,7 @@ function dim_usage
 
 # dim subcommand aliases (with bash 4.3+)
 if ! declare -n subcmd=dim_alias_${subcommand//-/_} &> /dev/null || \
-		test -z "$subcmd"; then
+		test -z "${subcmd:-}"; then
 	subcmd="$subcommand"
 fi
 
-- 
2.1.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux