0

I want to create an alias like this

alias kns='kubectl config set-context --current --namespace'

And add the required argument to --namespace (i.e. =default) on the command line. Is this possible?

I know I can create

alias kns='kubectl config set-context --current 

And add both the flag and argument on the command line

kns --namespace=default

But I want to avoid typing --namespace every time. So my question is really:

  • How do I concatenate an alias with some string without any spaces between?
Cyrus
  • 84,225
  • 14
  • 89
  • 153
davidlars
  • 3
  • 1

1 Answers1

0

$1 is the first argument. ${1:-default} uses the word default, if the first argument has been omitted or is empty.

kns ()
{
  kubectl config set-context --current --namespace="${1:-default}"
}
ceving
  • 21,900
  • 13
  • 104
  • 178