What is my default shell in linux

How to Change Shell in Linux

This quick tutorial shows how to check the running shell, available shell in the system and how to change the default shell in Linux.

This quick tutorial shows how to check the running shell, available shell in the system and how to change the default shell in Linux.

You probably are already aware that there are several shell available on Linux and other Unix-like systems. Bash is the default shell on almost all the Linux distributions but there are some other popular shells available such as:

Some of the shells provide additional features in a more user-friendly way. Take Fish shell for example. It partially starts showing you command hints based on your previous typed command. It’s quite handy if you don’t want remember the Linux terminal shortcuts all the time.

Let’s see a few things around shell in your Linux system.

How to know the default shell?

To know the default shell set for you in your Linux system, you can check the SHELL environment variable. Usually, the default shell is bash and it is shown like this:

How to see what shell are you currently using?

There is no single method that will tell you which shell you are using with 100% accuracy.

You can try either echo $0 that shows you an output like this:

or check the process using ps -p $$ like this:

ps -p $$ PID TTY TIME CMD 9625 pts/0 00:00:00 zsh

How to see all the shells available on your Linux system?

All the shells available on your Linux systems are listed in the file /etc/shells. You can use cat command or less command to view the content of the file.

# /etc/shells: valid login shells /bin/sh /bin/bash /bin/rbash /bin/dash /usr/bin/tmux /usr/bin/fish /bin/zsh /usr/bin/zsh

How to change the shell to use another one?

If you want to use a different shell, you can simply type its name and you’ll be logged into the new shell. For example, if you install zsh and want to use it, you can simply use:

You can enter exit to exit from the new shell and return to the previous one.

How to change the default shell in Linux permanently?

Suppose you liked the Fish shell a lot and you want to use it as your default shell so that every time you open the terminal or ssh into the system, you are using it instead of the default bash shell.

Linux allows you to change the default shell using the chsh command. The best way to change the default shell for your own logged in user is by specifying the shell name listed in the /etc/shells file with the -s option.

You must log out of the system so that the changes take into effect otherwise you’ll think that running chsh didn’t change the shell.

Читайте также:  Install linux and android

Did you notice that I had to specify the full path as it was listed in the /etc/shells file? If I had used chsh -s fish, it would have given me an error like “chsh: fish is an invalid shell”.

Which shell do you like?

Now that you know how to change shell, you may also read how to change users in Linux.

I hope this little article helped you to change the shell in Linux. If you have thought about changing the default shell, perhaps you use something other than the bash shell. Which shell is it? Why do you prefer it over the others?

Do share your views in the comments below.

Источник

What is the Default Shell in Linux Called?

What is the Default Shell in Linux Called?

A ‘Shell’ is an ‘Interactive Utility’ provided by Linux systems. Whenever we speak of the command line in Linux or Unix environment we are referring to the ‘Shell’. It works as a mid-man between the user and the system which takes input from the user and feeds that input to the system.

The Linux shell provides a way for users to start programs or manage and manipulate any data on the Linux system. The shell facilitates as a medium for the user to interact with the system through commands.

Command Prompt is the most fundamental and core part of the Shell in Linux and Unix systems. The $ character is the default prompt in most of the Linux distributions and more specifically in the distributions which use Bourne Shell. Command Prompt acts as an interface where you can enter the commands. These commands re then interpreted executed in the kernel. Shell command is the first program to execute when you first launch a terminal window.

In this brief article, you shall learn bout some basic facts about the Shells in Linux and also the question about the default shell in Linux shall be addressed.

Types Of Shell

In Linux, there are two major types of shells- Bourne Shell and C-type shell. Both types of Shell have some advantages and also drawbacks.

Let us see the specifications of both these types in the following sections.

Bourne Shell

Bourne Shell was written by Stephen Bourne at AT&T Bell Labs. Bourne Shell ( sh ) was the first to be introduced into the Linux systems. You can find this shell installed as /bin/sh on most of the Linux distributions.

Although Bourne Shell was pretty popular and preferred back then but it had some drawbacks. The ability to recall previous commands was missing in this Shell. sh lacked many modern capabilities like aliases and hence made it less effective.

Following are the subcategories of the Bourne Shell.

  • Bourne Shell ( sh )
  • Korn Shell ( ksh )
  • Bourne Again Shell ( bash )
  • POSIX Shell ( sh )

C-Type Shells

C-type shell was created using the C-programming language by Bill Joy. C-Shell or ‘ csh ‘ is seen as an upgrade over the Bourne Shell ( sh ). csh introduced many new features like command history and aliases which was missing in the Bourne Shell.

Although it was an upgrade over the Bourne shell, it had few challenges. Also one prominent issue with csh was that it required the user to have prior knowledge of the C-programming language as it was built on the basis of C-language.

Following are the subcategories of the C-type Shells.

On the Linux systems, you can find out different shells available on your system using the cat command. The information about the shells is located at the /etc/shells directory. Use the following command to find the details about the shells.

gaurav@ubuntu:~$ cat /etc/shells # /etc/shells: valid login shells /bin/sh /bin/dash /bin/bash /bin/rbash gaurav@ubuntu:~$ 

The Default Shell On Linux

To answer the question “Which is the default shell in Linux?”, the most appropriate answer would be the ‘ BASH ‘ (Bourne Again Shell). BASH is the most popular shell and hence found on most of the Linux distributions as the default shell.

Читайте также:  Linux зашифровать весь диск

To check your default shell in Linux, you can use the following command.

This means that the shell currently in use on my system is the BASH shell.

You can check the current version of the BASH in your Linux system using the following command:

Features Of BASH Shell

BASH is backwards compatible with the Bourne Shell ( sh ). BASH includes many prominent features from the Korn Shell ( ksh ) as well as the C-Shell ( csh ).

BASH offers many new features that were absent in its predecessors. And that undoubtedly makes the BASH shell an excellent improvement over its predecessors. Many new features like wildcarding, piping, tab-completion are the significant improvements that make BASH a preferred shell as the default for most of the Linux distributions.

Let us look at some notable features of Bash shell.

Command History: This simple command can save your effort to retype a lengthy command. Command History feature recalls the previously entered commands which can be navigated through the terminal by arrow keys.

Command-Line Editing: This feature is newly introduced with BASH. It allows the user to move freely onto the command line from left to right and right to left. This navigation on the terminal may seem normal now but this was a very significant improvement over its predecessors.

Aliases: This is a derived feature from the C-shell. It allows the users to type only the short name or command. The shell then translates this short command to the longer command.

One Dimensional Array: 1-D Arrays in BASH allows easy referencing of data. The manipulation of the lists of the data also becomes possible.

Startup Files: Startup Files are the scripts that Bash reads and executes when it is launched. Each file is assigned for a specific task.

Environment Security: BASH offers you an extraordinary feature of ‘Restricted Mode’. A BASH starting with the name rbash allows the shell to function in the restricted mode.

Due to all these notable features, the bash shell is a widely preferred shell in Linux and Unix-like systems. It is for the very same reason that it is accepted as the default shell for most of the Linux distributions.

Commands available with the BASH shell

BASH shell offers you a plethora of commands to make your work effortless and control all the actions on your system from your command line itself. Following are some of the fundamental commands BASH shell offers on the Linux distributions.

Note: The list of commands available on the BASH shell is NOT limited to only this table. These are some of the fundamental commands used for illustrative purpose.

Command Description
rm command used to delete a file
cp command used to delete a file or directory
touch command to create an empty file
mkdir command to create a new directory
pwd command to print the name of the present working directory
cd command to change the directory

Conclusion

After looking at all the basic and important features of the BASH shell, we can conclude that BASH shell is the popular shell out of the available options due to its powerful nature, user-friendly features and a huge basket of commands which make the user’s experience effortless. Also, we can safely say that BASH is the default shell on the Linux distributions.

Читайте также:  400 Bad Request

Источник

4 Ways to Check Which Shell You are Using on Linux

check user shell linux

Out of the box, Linux provides a wide variety of shells. There is bash (Bourne Again shell) shell which ships by default in many Linux distributions. We also have sh (Bourne Shell), tcsh (TC shell), csh (C shell), Zsh (Z shell) and ksh (Korn Shell).

Curious to know which shell you are using on your Linux system? In this guide, we explore different ways that you can use to check which shell you are currently using in Linux.

1. Using echo command

The Linux echo command is a built-in command that is used to print the output of a string which is passed as an argument. Additionally, you can use the echo command to check the shell that you are running commands in. To accomplish this, execute:

Output of echo $SHELL

The output shows that I am using the bash shell. Additionally, you can simply run the command:

Output of echo

To get the PID of the shell that you are currently in, run:

Output of echo $

2. Using ps command

Commonly used for listing running processes, the ps command in its basic format sheds light on the shell that you are using. Simply execute the command:

output of ps command

From the first line of the output, we can clearly see the PID of the shell and the last column prints out the type of shell, in this case — bash.

Alternatively, you can run the command:

Output of ps -p $

You can also use ps -p $$ -o args= which output just the shell name.

3. By viewing /etc/passwd file

The grep command can be used to probe the /etc/passwd file that contains attributes of the users such as username, user ID and group ID.

To display the shell used, invoke the command:

Using /etc/passwd file to show shell

At the very last segment, we get to see the bash used, in this case /bin/bash This also gives you a glimpse of which shell is opened first when you first log in to your system.

4. Using lsof command

Ordinarily, the lsof command, short for list of open files, is used to provide a list of open files on your system. However, when used with the -p $$ flag, it gives a pointer to the shell you are in when you look at the first column of the output.

For example, we can clearly see that we are on the bash shell.

Output of lsof -p $

How to check the valid login shells

We have seen various ways that you can employ to check the shell that you are currently in. If you want to know the valid shells on your system, check the /etc/shells file, This file will provide you with the full pathnames of valid login shells in your system. Using the cat command, view the file as shown:

Valid login shells

Conclusion

In this guide, we have shared simple but nifty ways that you can use to know which shell you are working on. This is important when writing scripts so that you can know how to start off writing the shebang header. We do hope that this tutorial was beneficial. Send us a shout and don’t forget to share this guide on your social platforms.

If this resource helped you, let us know your care by a Thanks Tweet. Tweet a thanks

Источник

Оцените статью
Adblock
detector