-1

So, I have a microk8s Kubernetes cluster running Nextcloud, and I want to run "occ" commands directly from the host, without the need to drill-down into the pod terminal.

eg: occ maintenance:mode --on where occ is actually microk8s kubectl exec -it nextcloud-dev-6f6f5db6f7-5rtm9 -- su -s /bin/bash www-data -c "php occ"

Using this post, I actually got very close, but I am having problems to pass arguments to the alias.

This is my entry on .bashrc:

alias occ='microk8s kubectl exec -it nextcloud-dev-6f6f5db6f7-5rtm9 -- su -s /bin/bash www-data -c "php occ $1"'

My guess is that the double quotes is messing with the argument, but not sure how to solve it.

Any ideas?

Edit: This question was marked as duplicated based on Make a Bash alias that takes a parameter?, and the answer is indeed buried there, and not tailored for my needs. The question in the other post is also misleading, as commented in one of its responses that explains my understanding of an alias that is: ...alias just adds a second name for something that already exists, and I would never have clicked on it because that discussion was out of context in regards what I was looking for. What I needed was the answer provided by hyperupcall (THANK YOU FOR THAT!), which used the same solution from Make a Bash alias that takes a parameter?, but within the context that includes Nextcloud, bashrc, and Kubernetes in the same sentence. I believe that this makes this question different enough to NOT be marked as a duplicate.

1 Answers1

1

Use a function:

occ() {
  microk8s kubectl exec -it nextcloud-dev-6f6f5db6f7-5rtm9 -- su -s /bin/bash www-data -c "php occ $*"
}

You cannot use variables like $1 inside of aliases and have them work like you think they do. Arguments after alises are simply appended on at the end, so you need to use a function.

hyperupcall
  • 869
  • 10
  • 21