From 27784fc75054622156a503986267c838bc190577 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 27 Jun 2025 22:40:41 -0500 Subject: [PATCH] Cleanup: Apply new script practices. Be more consistent about wrapping all variables in brackets. This helps make the code more consistent and also more compatible with other interpreters like ZSH. Don't use echo pipe syntax and instead use "<<<" redirection pipe syntax for passing variables to program calls. The grep commands should use either `-sho` or `-shoP`. --- install.sh | 60 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/install.sh b/install.sh index fb971b5..59f4119 100755 --- a/install.sh +++ b/install.sh @@ -83,8 +83,8 @@ install_main() { local enable_static_libraries="yes" local enable_includes="yes" - if [[ $# -gt 0 ]] ; then - t=$# + if [[ ${#} -gt 0 ]] ; then + t=${#} while [[ ${i} -lt ${t} ]] ; do let i=${i}+1 @@ -190,29 +190,29 @@ install_main() { fi else if [[ ${grab_next} == "path_build" ]] ; then - path_build=$(echo ${p} | sed -e 's|^//*|/|' -e 's|/*$|/|') + path_build=$(sed -e 's|^//*|/|' -e 's|/*$|/|' <<< ${p}) elif [[ ${grab_next} == "prefix" ]] ; then - destination_prefix=$(echo ${p} | sed -e 's|^//*|/|' -e 's|/*$|/|') + destination_prefix=$(sed -e 's|^//*|/|' -e 's|/*$|/|' <<< ${p}) elif [[ ${grab_next} == "bindir" ]] ; then - destination_programs=$(echo ${p} | sed -e 's|^//*|/|' -e 's|/*$|/|') + destination_programs=$(sed -e 's|^//*|/|' -e 's|/*$|/|' <<< ${p}) elif [[ ${grab_next} == "docdir" ]] ; then - destination_documentation=$(echo ${p} | sed -e 's|^//*|/|' -e 's|/*$|/|') + destination_documentation=$(sed -e 's|^//*|/|' -e 's|/*$|/|' <<< ${p}) elif [[ ${grab_next} == "etcdir" ]] ; then - destination_settings=$(echo ${p} | sed -e 's|^//*|/|' -e 's|/*$|/|') + destination_settings=$(sed -e 's|^//*|/|' -e 's|/*$|/|' <<< ${p}) elif [[ ${grab_next} == "includedir" ]] ; then - destination_includes=$(echo ${p} | sed -e 's|^//*|/|' -e 's|/*$|/|') + destination_includes=$(sed -e 's|^//*|/|' -e 's|/*$|/|' <<< ${p}) elif [[ ${grab_next} == "libdir" ]] ; then - destination_libraries=$(echo ${p} | sed -e 's|^//*|/|' -e 's|/*$|/|') + destination_libraries=$(sed -e 's|^//*|/|' -e 's|/*$|/|' <<< ${p}) elif [[ ${grab_next} == "work" ]] ; then - work=$(echo ${p} | sed -e 's|^//*|/|' -e 's|/*$|/|') + work=$(sed -e 's|^//*|/|' -e 's|/*$|/|' <<< ${p}) elif [[ ${grab_next} == "destination_libraries_static" ]] ; then - destination_libraries_static=$(echo ${p} | sed -e 's|^//*|/|' -e 's|/*$|/|') + destination_libraries_static=$(sed -e 's|^//*|/|' -e 's|/*$|/|' <<< ${p}) elif [[ ${grab_next} == "destination_libraries_shared" ]] ; then - destination_libraries_shared=$(echo ${p} | sed -e 's|^//*|/|' -e 's|/*$|/|') + destination_libraries_shared=$(sed -e 's|^//*|/|' -e 's|/*$|/|' <<< ${p}) elif [[ ${grab_next} == "destination_programs_static" ]] ; then - destination_programs_static=$(echo ${p} | sed -e 's|^//*|/|' -e 's|/*$|/|') + destination_programs_static=$(sed -e 's|^//*|/|' -e 's|/*$|/|' <<< ${p}) elif [[ ${grab_next} == "destination_programs_shared" ]] ; then - destination_programs_shared=$(echo ${p} | sed -e 's|^//*|/|' -e 's|/*$|/|') + destination_programs_shared=$(sed -e 's|^//*|/|' -e 's|/*$|/|' <<< ${p}) fi grab_next= @@ -269,29 +269,29 @@ install_main() { fi if [[ ${destination_prefix} != "" ]] ; then - if [[ $(echo ${destination_documentation} | grep -o '^/') == "" ]] ; then + if [[ $(grep -sho '^/' <<< ${destination_documentation}) == "" ]] ; then destination_documentation="${destination_prefix}${destination_documentation}" fi - if [[ $(echo ${destination_programs} | grep -o '^/') == "" ]] ; then + if [[ $(grep -sho '^/' <<< ${destination_programs}) == "" ]] ; then destination_programs="${destination_prefix}${destination_programs}" fi - if [[ $(echo ${destination_includes} | grep -o '^/') == "" ]] ; then + if [[ $(grep -sho '^/' <<< ${destination_includes}) == "" ]] ; then destination_includes="${destination_prefix}${destination_includes}" fi - if [[ $(echo ${destination_libraries} | grep -o '^/') == "" ]] ; then + if [[ $(grep -sho '^/' <<< ${destination_libraries}) == "" ]] ; then destination_libraries="${destination_prefix}${destination_libraries}" fi - if [[ $(echo ${destination_settings} | grep -o '^/') == "" ]] ; then + if [[ $(grep -sho '^/' <<< ${destination_settings}) == "" ]] ; then destination_settings="${destination_prefix}${destination_settings}" fi fi if [[ ${destination_libraries_static} != "" ]] ; then - if [[ $(echo ${destination_libraries_static} | grep -o '^/') == "" ]] ; then + if [[ $(grep -sho '^/' <<< ${destination_libraries_static}) == "" ]] ; then destination_libraries_static=${destination_libraries}${destination_libraries_static} fi else @@ -299,7 +299,7 @@ install_main() { fi if [[ ${destination_libraries_shared} != "" ]] ; then - if [[ $(echo ${destination_libraries_shared} | grep -o '^/') == "" ]] ; then + if [[ $(grep -sho '^/' <<< ${destination_libraries_shared}) == "" ]] ; then destination_libraries_shared=${destination_libraries}${destination_libraries_shared} fi else @@ -307,7 +307,7 @@ install_main() { fi if [[ ${destination_programs_static} != "" ]] ; then - if [[ $(echo ${destination_programs_static} | grep -o '^/') == "" ]] ; then + if [[ $(grep -sho '^/' <<< ${destination_programs_static}) == "" ]] ; then destination_programs_static=${destination_programs}${destination_programs_static} fi else @@ -315,7 +315,7 @@ install_main() { fi if [[ ${destination_programs_shared} != "" ]] ; then - if [[ $(echo ${destination_programs_shared} | grep -o '^/') == "" ]] ; then + if [[ $(grep -sho '^/' <<< ${destination_programs_shared}) == "" ]] ; then destination_programs_shared=${destination_programs}${destination_programs_shared} fi else @@ -650,7 +650,7 @@ install_perform_install() { if [[ ${failure} -eq 0 && -d ${path_build}${path_includes} && ${enable_includes} == "yes" ]] ; then for i in ${path_build}${path_includes}* ; do - file=$(echo ${i} | sed -e "s|^${path_build}${path_includes}||") + file=$(sed -e "s|^${path_build}${path_includes}||" <<< ${i}) break done @@ -681,7 +681,7 @@ install_perform_install() { if [[ -d ${path_build}${path_libraries}${path_static} && ${enable_static_libraries} == "yes" ]] ; then for i in ${path_build}${path_libraries}${path_static}* ; do - file=$(echo ${i} | sed -e "s|^${path_build}${path_libraries}${path_static}||") + file=$(sed -e "s|^${path_build}${path_libraries}${path_static}||" <<< ${i}) break done @@ -711,7 +711,7 @@ install_perform_install() { if [[ ${failure} -eq 0 && -d ${path_build}${path_libraries}${path_shared} && ${enable_shared_libraries} == "yes" ]] ; then for i in ${path_build}${path_libraries}${path_shared}* ; do - file=$(echo ${i} | sed -e "s|^${path_build}${path_libraries}${path_shared}||") + file=$(sed -e "s|^${path_build}${path_libraries}${path_shared}||" <<< ${i}) break done @@ -743,7 +743,7 @@ install_perform_install() { if [[ -d ${path_build}${path_programs}${path_static} && ${enable_static_programs} == "yes" ]] ; then for i in ${path_build}${path_programs}${path_static}* ; do - file=$(echo ${i} | sed -e "s|^${path_build}${path_programs}${path_static}||") + file=$(sed -e "s|^${path_build}${path_programs}${path_static}||" <<< ${i}) break done @@ -773,7 +773,7 @@ install_perform_install() { if [[ ${failure} -eq 0 && -d ${path_build}${path_programs}${path_shared} && ${enable_shared_programs} == "yes" ]] ; then for i in ${path_build}${path_programs}${path_shared}* ; do - file=$(echo ${i} | sed -e "s|^${path_build}${path_programs}${path_shared}||") + file=$(sed -e "s|^${path_build}${path_programs}${path_shared}||" <<< ${i}) break done @@ -804,7 +804,7 @@ install_perform_install() { if [[ ${failure} -eq 0 && -d ${path_build}${path_settings} && ${enable_settings} == "yes" ]] ; then for i in ${path_build}${path_settings}* ; do - file=$(echo ${i} | sed -e "s|^${path_build}${path_settings}||") + file=$(sed -e "s|^${path_build}${path_settings}||" <<< ${i}) break done @@ -834,7 +834,7 @@ install_perform_install() { if [[ ${failure} -eq 0 && -d ${path_build}${path_documentation} && ${enable_documentation} == "yes" ]] ; then for i in ${path_build}${path_documentation}* ; do - file=$(echo ${i} | sed -e "s|^${path_build}${path_documentation}||") + file=$(sed -e "s|^${path_build}${path_documentation}||" <<< ${i}) break done -- 1.8.3.1