Linux - Shell (Bourne compatible shells)

About

Os - Shell in Linux context

Management

Valid

The valid shell for a distribution are listed in the /etc/shells

/bin/sh
/bin/bash
/sbin/nologin
/bin/tcsh
/bin/csh
/bin/ksh

List

Several type of wiki/unix_shell have been developed:

Prompt

The following table shows the commonly used default UNIX® system prompt and superuser prompt for the C shell, Bourne shell, and Korn shell.

Shell Prompt
C shell machine_name%
C shell for superuser machine_name#
Bourne shell and Korn shell $
Bourne shell and Korn shell for superuser #

Current Shell

With the environment variable $SHELL

echo $SHELL
/bin/bash

With ps

ps -p $$
PID TTY          TIME CMD
 4104 pts/1    00:00:00 bash

where:

  • $ is a bash special parameter that contains the PID (process identification number) of the current process which is your shell

Then running a ps on that number displays a process status listing of your shell.

Zero (0)

In bash, the special parameter 0 expands to the name of the shell or shell script. This is set at shell initialization. If bash is invoked with a file of com- mands, $0 is set to the name of that file.

If bash is started with the -c option, then $0 is set to the first argument after the string to be executed, if one is present. Otherwise, it is set to the file name used to invoke bash, as given by argument zero.

# echo $0
/bin/bash

default shell for a user

The utility chsh (Change the login shell) is used to change it.

It will change it in the /etc/password file

absolute path name

See the special parameter $_

Startup

The following startup files 1) are sourced when the shell is

  • an interactive non-login shell:
  • a non-interactive shell:
    • $BASH_ENV. The value should points to a file 2)
    • /etc/bashrc or /etc/bash.bashrc (loaded by /etc/profile)
  • a login shell:
    • /etc/profile and /etc/profile.d/*.sh: system-wide .profile file
    • ~/.bash_profile,
    • ~/.bash_login,
    • and ~/.profile See login shell

Interactive

When the shell:

  • is in REPL mode, it's Interactive
  • is executing a command, it's non-interactive

A executable bash script is non-interactive.

See Bash - Interactive Shell

Login

A login shell is just an option that will execute scripts at login (start) and end (logout) time. See What is a Login Shell?

Example with Docker

The entrypoint is a:

  • non-interactive
  • non-login script

A bash instance within a Docker exec command will be:

  • an interactive shell thanks to the i flag of docker
  • a login shell thanks to the l flag of bash

Example:

  • non-login interactive shell
docker exec -ti containerName bash
  • login interactive shell
docker exec -ti containerName bash -l

Documentation / Reference





Discover More
Bash Liste Des Attaques Ovh
Bash - (Builtin|Intern|System|Reserved|Shell) variable name

Reserved variable name are named that have a special meaning for the bash shell. PS1 defines the shell's command-line prompt. HOME defines the home directory for a user. PATH defines a list...
Bash Liste Des Attaques Ovh
Bash - (Environment) Variable

A variable is a parameters referenced by a name. parameter A variable has: a value and zero or more attributes (such as integer, ...). Attributes are assigned using the declare builtin command....
Bash Liste Des Attaques Ovh
Bash - (GNU) Bourne-Again SHell

Bash is an sh-compatible shell. It is intended to conform to the IEEE POSIX P1003.2/ISO 9945.2 Shell and Tools standard. Bash is the shell, or command language interpreter, that will appear in the GNU...
Bash Liste Des Attaques Ovh
Bash - Bash cli

Bash is an sh-compatible a shell that executes commands read: from the standard input or from a file (script). In addition to the single-character shell options documented in the description...
Bash Liste Des Attaques Ovh
Bash - Exit Builtin command

exit is a builtin command and cause the shell to exit with a given exit status. n is the exit status of n. If n is omitted,the exit status is that of the last command executed. A function...
Bash Liste Des Attaques Ovh
Bash - Interactive Shell

An Interactive shell is created when bash is: started: without non-optionarguments without the -c option whose standard input and error are both connected to terminals (as determined by isatty(3)),...
Bash Liste Des Attaques Ovh
Bash - Special Parameter

Special parameters are Parameters treated specially. metacharacter ?? These parameters may only be referenced; assignment to them is not allowed. Positional parameter expansion Star () At...
Bash Liste Des Attaques Ovh
Bash Shell and (Unix|Linux) Utilities (XCU)

Bash is a POSIX compliant shell, known as the Bourne-Again. It means that this is scripting language used in a terminal based around The articles of this section are over: the Bash (Bourne-Again...
Fish Shell

fish is a shell for Linux based OS (macOS, ..) Idea
How to write a Linux Script (Shebang)?

This page is the creation of Script in Linux. They can be written in many languages does not need an extension must be given the execution permission where the first line called the Shebang_(Unix)shebang...



Share this page:
Follow us:
Task Runner