Which shell is used in linux

How can I know which shell I am using?

I am writing a shell script. The tutorial that I am reading have the first line like this : #!/usr/bin/env bash/ but it isn’t working for me. ( error : no such directory ) How can I find out which bash I am using and where is it located? Appreciate for any advice and help. Thanks a lot. It works now. solution is #!/usr/bin/env bash Another problem: Why it just can’t read the word ‘restart’ my code in the start.sh:

#!/usr/bin/env bash/ RESTART="apachectl restart" $RESTART 
Usage: /usr/local/apache2/bin/httpd [-D name] [-d directory] [-f file] [-C "directive"] [-c "directive"] [-k start|restart|graceful|graceful-stop|sto p] [-v] [-V] [-h] [-l] [-L] [-t] [-S] Options: -D name : define a name for use in directives -d directory : specify an alternate initial ServerRoot -f file : specify an alternate ServerConfigFile -C "directive" : process directive before reading config files -c "directive" : process directive after reading config files -e level : show startup errors of level (see LogLevel) -E file : log startup errors to file -v : show version number -V : show compile settings -h : list available command line options (this page) -l : list compiled in modules -L : list available configuration directives -t -D DUMP_VHOSTS : show parsed settings (currently only vhost settings) -S : a synonym for -t -D DUMP_VHOSTS -t -D DUMP_MODULES : show all loaded modules -M : a synonym for -t -D DUMP_MODULES -t : run syntax check for config files 

why is it like that? it seems that it can read the word restart. Thank you all! I have fixed it now. solution: edit the file in unix (vim/nano and whatever but not in windows)

Источник

8 Types of Linux Shells

Linux comes with several different shells. Although a distribution has a default shell, users can change to another type or install a new one.

If you’re looking to change your default shell, knowing the different available types helps provide a clear overview of the possible options.

This article showcases the importance and features of eight different Linux shells.

8 Types Of Linux Shells

What is a Linux Shell and Why is it Important?

A shell is a command-line interpreter program that parses and sends commands to the operating system. This program represents an operating system’s interactive interface and the kernel’s outermost layer (or shell). It allows users and programs to send signals and expose an operating system’s low-level utilities.

OS layers communication

The terminal program (or terminal emulator) enables interaction with the system’s utilities. When we run any command in the terminal, such as ls or cat, the shell parses, evaluates, searches for, and executes the corresponding program, if found.

Types of Linux Shells

Linux offers different shell types for addressing various problems through unique features. The shells developed alongside Unix often borrowed features from one another as development progressed.

Читайте также:  Linux mysql забыл пароль

Below is a brief overview of different shell types and their features.

1. Bourne Shell (sh)

The Bourne shell was the first default shell on Unix systems, released in 1979. The shell program name is sh, and the traditional location is /bin/sh. The prompt switches to $, while the root prompt is #.

Bourne shell sh example commands

The Bourne shell quickly became popular because it is compact and fast. However, sh lacks some standard features, such as:

  • Logical and arithmetic expansion.
  • Command history.
  • Other comprehensive features, such as autocomplete.

Modern Unix-like systems have the /bin/sh executable file. The program does not start the Bourne shell but acts as an executable file pointing to the default system shell.

/bin/sh link Ubuntu dash CentOS bash

For most systems, the hard or symbolic link points to bash, while on Ubuntu and Debian, the link is to dash. In both cases, the link mimics the Bourne shell as much as possible.

2. C Shell (csh)

The C shell (csh) is a Linux shell from the late 1970s whose main objective was to improve interactive use and mimic the C language. Since the Linux kernel is predominantly written in C, the shell aims to provide stylistic consistency across the system.

The path to the C shell executable is /bin/csh. The prompt uses % for regular users and # for the root user.

C shell csh example commands

New interactive features included:

  • History of the previous command.
  • User-defined aliases for programs.
  • Relative home directory (~).
  • Built-in expression grammar.

The main drawbacks of the C shell are:

  • Syntax inconsistencies.
  • No support for standard input/output (stdio) file handles or functions.
  • Not fully recursive, which limits complex command handling.

The C shell improved readability and performance compared to the Bourne shell. The interactive features and innovations in csh influenced all subsequent Unix shells.

3. TENEX C Shell (tcsh)

The TENEX C shell (tcsh) is an extension of the C shell (csh) merged in the early 1980s. The shell is backward compatible with csh, with additional features and concepts borrowed from the TENEX OS.

The TENEX C shell executable path is in /bin/tcsh. The user prompt is hostname:directory> while the root prompt is hostname:directory# . Early versions of Mac OS and the default root shell of FreeBSD use tcsh.

TENEX C shell tcsh example commands

Additional features of the shell include:

  • Advanced command history.
  • Programmable autocomplete.
  • Wildcard matching.
  • Job control.
  • Built-in where command.

Since tcsh is an extension of the C shell, many drawbacks persist in the extended version.

4. KornShell (ksh)

The KornShell (ksh) is a Unix shell and language based on the Bourne shell (sh) developed in the early 1980s. The location is in /bin/ksh or /bin/ksh93, while the prompt is the same as the Bourne shell ( $ for a user and # for root).

Korn shell ksh example commands

The shell implements features from the C shell and Bourne shell, aiming to focus on both interactive commands and programming features. The KornShell adds new features of its own, such as:

  • Built-in mathematical functions and floating-point arithmetic.
  • Object-oriented programming.
  • Extensibility of built-in commands.
  • Compatible with the Bourne shell.

The shell is faster than both the C shell and the Bourne shell.

5. Debian Almquist Shell (dash)

The Debian Almquist Shell (dash) is a Unix shell developed in the late 1990s from the Almquist shell (ash), which was ported to Debian and renamed.

Читайте также:  Чем редактировать svg linux

Dash is famous for being the default shell for Ubuntu and Debian. The shell is minimal and POSIX compliant, making it convenient for OS startup scripts.

The executable path is /bin/dash, in addition to /bin/sh pointing to /bin/dash on Ubuntu and Debian. The default and root user prompt is the same as in the Bourne shell.

Debian Almquist shell dash example commands

  • Execution speeds up to 4x faster than bash and other shells.
  • Requires minimal disk space, CPU, and RAM compared to alternatives.

The main drawback is that dash is not bash-compatible. The features not included in dash are known as «bashisms.» Therefore, bash scripts require additional reworkings of bashisms to run succesfully.

6. Bourne Again Shell (bash)

The Bourne Again shell is a Unix shell and command language created as an extension of the Bourne shell (sh) in 1989. The shell program is the default login shell for many Linux distributions and earlier versions of macOS.

The shell name shortens to bash, and the location is /bin/bash. Like the Bourne shell, the bash prompt is $ for a regular user and # for root.

Bourne again shell bash example commands

Bash introduces features not found in the Bourne shell, some of which include:

  • Brace expansion.
  • Command completion.
  • Basic debugging and signal handling.
  • Command history.
  • Conditional commands, such as the bash if and bash case statements.
  • Heredoc support.

Note: Some features are not unique to Bash, but rather borrowed from other shells.

Since bash is a superset of the Bourne shell, most sh scripts execute in bash without any additional changes.

7. Z Shell (zsh)

The Z shell (zsh) is a Unix shell created as an extension for the Bourne shell in the early 1990s. The feature-rich shell borrows ideas from ksh and tcsh to create a well-built and usable alternative.

The executable location is in /bin/zsh. The prompt is user@hostname location % for regular users and hostname# for the root user. The Z shell is the default shell of Kali Linux and Mac OS.

Z shell zsh example commands

Some new features added to the zsh include:

  • Shared history among all running shell sessions.
  • Improved array and variable handling.
  • Spelling corrections and command name autofill.
  • Various compatibility modes.
  • Extensibility through plugins.

The shell is highly configurable and customizable due to the community-driven support through the Oh My Zsh framework.

8. Friendly Interactive Shell (fish)

The Friendly Interactive Shell (fish) is a Unix shell released in the mid-2000s with a focus on usability. The feature-rich shell does not require additional configuration, which makes it user-friendly from the start.

The default executable path is /usr/bin/fish. The user prompt is user@hostname location> , while the root prompt is root@hostname location# .

Friendly interactive shell fish example commands

Features in the shell include:

  • Advanced suggestions/tab completion based on the current directory history.
  • Helpful syntax highlighting and descriptive error messages.
  • Web-based configuration.
  • Command history with search options.

The main drawback of fish is non-POSIX compliance. However, the developers aim to improve flawed designs from POSIX.

After reading about several different shell types in this article, you have a better overview of the available Linux shells. Other shells exist for specific use cases, and every shell type addresses different problems.

Источник

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