0

I'm creating a bash script file for doing some operation as

1. Do some operations
2. Go inside kubernetes cluster (kubectl exec -it <pod> --bash)
3. Copying some files 
4. Connecting to mongo
5. Adding some data to collections
6. Exit from mongo -----------> step 1
7. Exit from k8s cluster -------> step2
8. Do some operations 

Problem : I'm getting problem in Exit command( step1 and step2). It is exiting from script file not from mongo or k8s cluster.

What I have tried

It worked if I'm passing all commands inside options "c" as below:

kubectl exec -it <pod> --bash -c "echo text && exit"

But If I'm using any function( which I created in script) with "c" options then it din't work.

test() { // some code }
kubectl exec -it <pod> --bash -c "test && exit" // couldn't find test

Also -c option is not working with mongo command.

Does anyone have any idea about it?

Dipti
  • 106
  • 1
  • 8
  • 1
    [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Digvijay S Jul 27 '20 at 10:57
  • 3
    Duplicate of [Exporting a function in shell](https://stackoverflow.com/questions/1885871/exporting-a-function-in-shell) – oguz ismail Jul 27 '20 at 11:08

0 Answers0