Skip to content

Commit

Permalink
Fix for #133 (#134)
Browse files Browse the repository at this point in the history
Change `join` function for assembling `command_to_tail`
to prevent that it is removed from the final eval'ed command. This is
necessary for newer BASH versions where this character had to be escaped
in the previous implementation. This version has been verified with
BASH 5.2.2 and 5.0.7.
  • Loading branch information
stonemaster authored Nov 29, 2022
1 parent fbe937a commit 9530280
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions kubetail
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,23 @@ fi

# Join function that supports a multi-character separator (copied from http://stackoverflow.com/a/23673883/398441)
function join() {
# $1 is return variable name
# $2 is sep
# $3... are the elements to join
local retname=$1 sep=$2 ret=$3
shift 3 || shift $(($#))
printf -v "$retname" "%s" "$ret${@/#/$sep}"
# $1 is sep
# $2... are the elements to join
local sep="$1"
shift

local F=0
for x in "$@"
do
if [[ F -eq 1 ]]
then
echo -n "$sep"
else
F=1
fi
echo -n "$x"
done
echo
}

# Check if pod query contains a comma and we've not specified "regex" explicitly,
Expand All @@ -261,7 +272,7 @@ if [[ "${pod}" = *","* ]] && [ ! "${regex}" == 'regex' ]; then
IFS=',' read -r -a pods_to_match <<< "${pod}"

# Join all pod names into a string with ".*|.*" as delimiter
join pod ".*|.*" "${pods_to_match[@]}"
pod=$(join ".*|.*" "${pods_to_match[@]}")

# Prepend and initial ".*" and and append the last ".*"
pod=".*${pod}.*"
Expand Down Expand Up @@ -389,7 +400,7 @@ then
fi

# Join all log commands into one string separated by " & "
join command_to_tail " & " "${logs_commands[@]}"
command_to_tail=$(join " & " "${logs_commands[@]}")

# Aggregate all logs and print to stdout
# Note that tail +1f doesn't work on some Linux distributions so we use this slightly longer alternative
Expand Down

0 comments on commit 9530280

Please sign in to comment.