0

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

  • @KoenG. Right. Now I suggest copying and pasting those comments into a single answer. If you had done so before I read this question, you would have received +1 vote from me. – TOOGAM Jul 24 at 12:16
  • @African_king could you explain what you mean by swichting_/_changing the shell? What is your main/default shell you want this to execute in? If you just want to write a script which is executed by bash the shebang is already sufficient for the commands to be executed by bash. If this is not what you want please explain why. – acran Jul 25 at 17:11
2

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.

| improve this answer | |
  • I want the script to temporarily switch to bash to execute some commands thanks – African_king Jul 24 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.