Types of shell

  • /etc/shells: This file contains a list of shells installed on the system that users are permitted to use. When you run cat /etc/shells, you’ll see output similar to this:

user@host:$ cat /etc/shells
/bin/sh
/bin/bash
/usr/bin/zsh
  • echo $0: This command prints the name of the current running shell. The output might look like -bash or /bin/zsh, indicating which shell you’re using at the moment.

user@host:$ echo $0
-bash

How to specify the shell type?

In a shell script, you can specify which shell type should to be used by including a shebang (#!) at the beginning of the script. The shebang is followed by the path to the shell’s executable.

Here’s how you can do it:

  1. Bash Shell: If you want to use Bash, you would start your script with:

    #!/bin/bash
  2. Z Shell: For Zsh, the shebang would be:

    #!/usr/bin/zsh
  3. C Shell: For Csh, you would use:

    #!/bin/csh

This line tells the system that the following script should be run with the specified shell. It’s important to note that the shebang line must be the very first line in the script file.

When you make the script executable and run it, the system reads the shebang line to determine which interpreter to use to execute the script. This is particularly useful when scripts are being shared across different environments where the default shell might differ.

Last updated