How to Restart Bash Without Restarting the Terminal?

In Linux, the Bash shell is the default shell used in most distributions. The Bash shell is responsible for interpreting user commands and executing them. Sometimes, users may need to restart the Bash shell without restarting the entire terminal application. This can be beneficial when users have changed the Bash environment or are experiencing issues with the shell.

This guide will offer to restart the Bash shell from the terminal without restarting the terminal application.

  • Method 1: Use the “exec bash” Command
  • Method 2: Use the “kill” Command

Method 1: Use the “exec bash” Command

To restart the Bash shell without restarting the terminal application, use the “exec bash” command. The “exec” command replaces the current process with a new process. In this case, replace the current Bash shell process with a new instance of the Bash shell:

$ exec bash

The output shows that a new instance of the Bash shell has been restarted.

To check the current shell that is running, type the “echo” command with the “$SHELL” variable:

$ echo $SHELL

The output shows the path to the shell binary “/bin/bash” that users are currently running the Bash shell.

Method 2: Use the “kill” Command

The “kill” command sends a signal to a process, which can be used to terminate the process. To use the kill command, we need to get the process id of the current shell via the command: 

$ echo $$

The output shows that the process id of running the Bash shell is 22133.

Then, type the “kill -HUP [PID]” command into the terminal by replacing the PID of the current shell. In our case, specify the process id 22133 to kill the specified process:

$ kill -HUP 22133

It terminates the Bash shell, and users can restart it using the “CTRL+ALT+T” command. 

Conclusion

To restart the Bash shell without restarting the terminal application, simply type the “exec bash” command into the terminal and press Enter. This command replaces the current process with the Bash shell. It saves time and helps users to troubleshoot any issues with the Bash shell. In addition, users can type the “kill -HUP [PID]” command by replacing “[PID]” with the PID of the current shell and restart via the “CTRL+ALT+T” key.

This article has explained all possible methods to restart Bash from the terminal without restarting the entire terminal application in Linux.