#1509 PR merged: Add function to test for 'real value'

Labels: enhancement, cleanup, fixed / solved / done

jsmeix opened issue at 2017-09-21 12:23:

The new contains_visible_char function tests
whether or not its arguments contain at least one 'real value'
where 'real value' means to be neither empty nor only blank
or control characters.

Currently it is already used in the UserInput function and in the
get_device_name UdevSymlinkName UdevQueryName
functions in lib/layout-functions.sh and
in 950_check_missing_programs.sh

@schabrolles
the contains_visible_char function should be in particular
useful for you when you like to ensure a value is
neither empty nor blank.

Note that using plain

test $var && echo "var is neither empty nor blank"

without quoting $var only works when var contains
at most one single word because it fails for strings:

# var='foo bar'

# test $var && echo "var is neither empty nor blank"
-bash: test: foo: unary operator expected

In contrast the contains_visible_char function works
basically for any arguments, e.g. even for things like

# arr=( '  ' '' '   ' )

# contains_visible_char "${arr[@]}" && echo y || echo n
n

# arr=( '  ' '' '   ' x )

# contains_visible_char "${arr[@]}" && echo y || echo n
y

jsmeix commented at 2017-09-21 12:44:

@schabrolles
many thanks for the prompt review!

jsmeix commented at 2017-09-21 12:51:

For the fun of "in the good old days...":
https://github.com/rear/rear/pull/1509/commits/929474f29877f15d3754e160ffcaee7de70aee52
contains my awkward attempts
to test for 'neither empty nor blank'
that I had used before ;-)


[Export of Github issue for rear/rear.]