From 5d060fdf7b25a00b3449f5fff7e961abb9899e1b Mon Sep 17 00:00:00 2001 From: "David A. Pimentel" Date: Thu, 4 Sep 2025 09:33:47 -0600 Subject: [PATCH] Filter duplicate ControlPath entries and skip all empty lines in ~/.ssh/config file. --- cmc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmc b/cmc index 3fdc080..8da4e56 100755 --- a/cmc +++ b/cmc @@ -72,15 +72,16 @@ config_control_path() { # Extract ControlPath from SSH config local _result _result_count _result=$(awk \ - 'tolower($1) ~ /^controlpath$/ { + '/^ *#/ || /^ *$/{next} + tolower($1) ~ /^controlpath$/ { if ( tolower($2) !~ /^none$/ ) { print $2 } - }' ${SSH_CONFIG}) + }' ${SSH_CONFIG} | sort -u) if [[ -n "${_result}" ]] then # Only a single ControlPath should be specified - _result_count=$(echo "${_result}" | sort -u | wc -l) + _result_count=$(echo "${_result}" | wc -l) if (( _result_count > 1 )) then error_exit "multiple ControlPaths specified: ${_result}"