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?
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.
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!"
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With