Search code examples
linuxcloudera-quickstart-vm

How to execute linux commands in the shell opened through /bin/bash


I am new to Linux stuff and would like to know how to run command while opening the shell through /bin/bash?

Eg the steps that I want to perform:

Step1: Run the docker exec command to start the quickstart virtual machine.

$ docker exec -it 7f8c1a16e5b2 /bin/bash

Step2: The above command gives the handle of the quickstart vm on the console. Now I want to run the below command by default when ever some one starts the docker quickstart console (step 1)

cd
. ./.bash_profile

I need some guidance on how to do this. Obviously, putting all these statements in one shell script isn't helping as the commands of Step2 are to be executed in the newly opened shell (of quickstart vm). The idea is to put all these statements in a single shell script and execute it when we want to get hold of the session within the VM console.


Solution

  • You can pass the commands you want to be executed inside the container to bash with the -c option.

    That would look something like this:

    docker exec -it 7f8c1a16e5b2 /bin/bash -c "cd && . ./.bash_profile && /bin/bash"