Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash script starting new shell and continuing to run commands [duplicate]

I'm a complete noob to writing bash scripts. I'm trying to do the following:

#!/bin/bash

mkdir New_Project
cd New_Project
pipenv install ipykernel
pipenv shell
python -m ipykernel install --user --name==new-virtual-env
jupyter notebook

The problem I'm having is that after it executes pipenv shell, it starts the new shell and then doesn't execute the last two commands. When I exit the new shell it then tries to execute the remaining lines. Is there any way to get a script to run all of these commands from start to finish?

like image 782
Austin Avatar asked Jan 02 '18 06:01

Austin


People also ask

How do you run multiple commands sequentially in shell script?

Using the Semicolon (;) Operator For instance, if there are two commands: command A and command B, using the semicolon operator in between them ensures that both the first and the second command get executed sequentially regardless of the output of the first command.

How do you continue a loop in bash?

Using Bash Continue with a for LoopUse the continue statement inside a conditional if to control the flow of a for : #!/bin/bash for i in {1.. 10} do if [[ $i == '9' ]] then echo "Number $i!" continue fi echo "$i" done echo "Done!"

How do you continue a loop in shell?

Skip an Iteration with continue Statement This can be done with a continue statement. The continue statement will skip the execution of the code block when a certain condition is met and the control is passed back to the loop statement for the next iteration.

How do you run multiple scripts one after another but only after previous one got completed?

Using wait. We can launch a script in the background initially and later wait for it to finish before executing another script using the wait command. This command works even if the process exits with a non-zero failure code.


1 Answers

As per the manual :

shell will spawn a shell with the virtualenv activated.

which is not what you need. Instead use run :

run will run a given command from the virtualenv, with any arguments forwarded (e.g. $ pipenv run python).

In your case, something like

pipenv run python -m ipykernel install --user --name==new-virtual-env
like image 96
sjsam Avatar answered Nov 14 '22 17:11

sjsam