TransWikia.com

Can I change my terminal environment to bash shell using a script and then execute other commands after changing the shell in the same script?

Super User Asked by African_king on December 27, 2021

I am trying to write a script that sets my main terminal to use bash shell. I know the #!/bin/bash will call all the commands in the script to be run with the bash shell but what I want is a script that specifically that changes the shell of my terminal to bash.

for example: (this is how my terminal looks like when it is opened.)

$

when i want to set the terminal to bash I manually type the bash command and press enter.

$bash

outcome:

[tyg@rooto ~]$

The problem is if I write a script using the above command it works but any command after the bash command in the script fails to execute.
for example

#!/bin/bash
bash
echo "setting terminal environment to bash"
echo "success"

output:

[tyg@rooto ~]$ 

Expected output: (something like this)

[tyg@rooto ~]$ setting terminal environment to bash
[tyg@rooto ~]$ success

or (Like this)

[tyg@rooto ~]$
[tyg@rooto ~]$ setting environment
[tyg@rooto ~]$ success

any of the above is what I assume should be expected. Why are the two echo commands in the script failing to execute and is there a fix to this. Thanks

One Answer

Your other commands don't execute because bash does not finish until you exit it. I'm not sure what you're trying to achieve here, but look into .bashrc if you want commands to always run when starting bash. If you always want to use bash, just write bash in the equivalent file for your current main shell or change your default shell in the /etc/passwd file.

If you want a script to temporarily switch to bash to execute some commands but don't want to have interactivity with that bash shell, you can look into calling bash with a here document in your main script.

Answered by Koen G. on December 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP