Skip to content

Instantly share code, notes, and snippets.

View tmacam's full-sized avatar

Tiago Alves Macambira tmacam

View GitHub Profile
@tmacam
tmacam / chcluster2.sh
Created September 29, 2023 22:56
Another approach to change kubectl context
#!/bin/bash
set -e
function listContexts() {
kubectl config get-contexts | sed -e 's/^ /off/' -e 's/^\*/on/' -e 1d | awk '{printf("%i\n%s\n", (NR-1),$2)}'
}
# https://stackoverflow.com/questions/11426529/reading-output-of-a-command-into-an-array-in-bash
IFS=$'\n' read -r -d '' -a contexts < <( listContexts && printf '\0' )