diff options
author | jpaetzel <jpaetzel@FreeBSD.org> | 2011-03-27 16:57:54 +0000 |
---|---|---|
committer | jpaetzel <jpaetzel@FreeBSD.org> | 2011-03-27 16:57:54 +0000 |
commit | c0b9051b174edd52b1c981a25a28d77d5133a049 (patch) | |
tree | 7685cacc260db6392774e2cc0fe2507f4afd24ba /usr.sbin/pc-sysinstall/backend/functions-parse.sh | |
parent | 79f5bd9d163ed51b54be37305ac97c975667db20 (diff) | |
download | FreeBSD-src-c0b9051b174edd52b1c981a25a28d77d5133a049.zip FreeBSD-src-c0b9051b174edd52b1c981a25a28d77d5133a049.tar.gz |
Fix a syntax error in a little-used function.
Replace expr with $(())
Replace grep > /dev/null with grep -q
Replace "$?" = "0" with $? -eq 0 in tests
Consolidate export statements with variable assignment
Replace tests for ! -z with -n
Approved by: kib (mentor)
Diffstat (limited to 'usr.sbin/pc-sysinstall/backend/functions-parse.sh')
-rwxr-xr-x | usr.sbin/pc-sysinstall/backend/functions-parse.sh | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/usr.sbin/pc-sysinstall/backend/functions-parse.sh b/usr.sbin/pc-sysinstall/backend/functions-parse.sh index 11bba10..4f96ca3 100755 --- a/usr.sbin/pc-sysinstall/backend/functions-parse.sh +++ b/usr.sbin/pc-sysinstall/backend/functions-parse.sh @@ -31,10 +31,9 @@ # which gets the value of a setting in the provided line get_value_from_string() { - if [ ! -z "${1}" ] + if [ -n "${1}" ] then - VAL="`echo ${1} | cut -d '=' -f 2`" - export VAL + export VAL="`echo ${1} | cut -d '=' -f 2`" else echo "Error: Did we forgot to supply a string to parse?" exit 1 @@ -44,10 +43,9 @@ get_value_from_string() # Get the value from the cfg file including spaces get_value_from_cfg_with_spaces() { - if [ ! -z "${1}" ] + if [ -n "${1}" ] then - VAL=`grep "^${1}=" ${CFGF} | head -n 1 | cut -d '=' -f 2` - export VAL + export VAL=`grep "^${1}=" ${CFGF} | head -n 1 | cut -d '=' -f 2` else exit_err "Error: Did we forgot to supply a setting to grab?" fi @@ -57,10 +55,9 @@ get_value_from_cfg_with_spaces() # Get the value from the cfg file get_value_from_cfg() { - if [ ! -z "${1}" ] + if [ -n "${1}" ] then - VAL=`grep "^${1}=" ${CFGF} | head -n 1 | cut -d '=' -f 2 | tr -d ' '` - export VAL + export VAL=`grep "^${1}=" ${CFGF} | head -n 1 | cut -d '=' -f 2 | tr -d ' '` else exit_err "Error: Did we forgot to supply a setting to grab?" fi @@ -70,7 +67,7 @@ get_value_from_cfg() # 1 = setting we are checking, 2 = list of valid values if_check_value_exists() { - if [ ! -z "${1}" -a ! -z "${2}" ] + if [ -n "${1}" -a -n "${2}" ] then # Get the first occurance of the setting from the config, strip out whitespace @@ -104,7 +101,7 @@ if_check_value_exists() # 1 = setting we are checking, 2 = list of valid values check_value() { - if [ ! -z "${1}" -a ! -z "${2}" ] + if [ -n "${1}" -a -n "${2}" ] then # Get the first occurance of the setting from the config, strip out whitespace VAL=`grep "^${1}" ${CFGF} | head -n 1 | cut -d '=' -f 2 | tr -d ' '` @@ -129,12 +126,12 @@ check_value() # 1 = values to confirm exist file_sanity_check() { - if [ ! -z "$CFGF" -a ! -z "$1" ] + if [ -n "$CFGF" -a -n "$1" ] then for i in $1 do - grep "^${i}=" $CFGF >/dev/null 2>/dev/null - if [ "$?" = "0" ] + grep -q "^${i}=" $CFGF 2>/dev/null + if [ $? -eq 0 ] then LN=`grep "^${i}=" ${CFGF} | head -n 1 | cut -d '=' -f 2 | tr -d ' '` if [ -z "${LN}" ] @@ -173,11 +170,11 @@ merge_config() while read newline do - echo ${newline} | grep "^#" >/dev/null 2>/dev/null - if [ "$?" != "0" ] ; then + echo ${newline} | grep -q "^#" 2>/dev/null + if [ $? -ne 0 ] ; then VAL="`echo ${newline} | cut -d '=' -f 1`" - cat ${OLDCFG} | grep ${VAL} >/dev/null 2>/dev/null - if [ "$?" != "0" ] ; then + cat ${OLDCFG} | grep -q ${VAL} 2>/dev/null + if [ $? -ne 0 ] ; then if [ "${FOUNDMERGE}" = "NO" ] ; then echo "" >> ${FINALCFG} echo "# Auto-merged values from newer ${NEWCFG}" >> ${FINALCFG} @@ -219,7 +216,7 @@ get_next_cfg_line() while read line do if [ "$FOUND" = "0" ] ; then - VAL="$line" ; export VAL + export VAL="$line" return fi if [ "$line" = "${CURLINE}" ] ; then @@ -228,5 +225,5 @@ get_next_cfg_line() done <${CURFILE} # Got here, couldn't find this line or at end of file, set VAL to "" - VAL="" ; export VAL + export VAL="" }; |