577, Gold Plaza, Punjab Jewellers, M.G. Road, Opp. Treasure Island Mall

Linux shell

CH932Linux shell is a user interface used for executing the commands. Shell is a program the user uses for executing the commands. In UNIX, any program can be the users shell.

Types of Shells in Linux

sh ( Bourne Shell ): The original shell still used on UNIX systems and in UNIX-related environments. This is the basic shell, a small program with few features. While this is not the standard shell, it is still available on every Linux system for compatibility with UNIX programs.

bash ( Bourne Again shell ): The standard GNU shell, intuitive and flexible. Probably most advisable for beginning users while being at the same time a powerful tool for the advanced and professional user. On Linux, bash is the standard shell for common users. This shell is a so-called superset of the Bourne shell, a set of add-ons and plug-ins. This means that the Bourne Again shell is compatible with the Bourne shell: commands that work in sh, also work in bash. However, the reverse is not always the case.

csh ( C shell ): the syntax of this shell resembles that of the C programming language sometimes asked for by programmers.

tcsh ( TENEX C shell ): a superset of the common C shell, enhancing user-friendliness and speed. That is why some also call it the Turbo C shell.

ksh ( the Korn shell ): sometimes appreciated by people with a UNIX background. A superset of the Bourne shell; with standard configuration a nightmare for beginning users.

The file /etc/shells gives an overview of known shells on a Linux system.

[root@armourinfosec /]# vim /etc/shells

To switch from one shell to another, just enter the name of the new shell in the active terminal.

[root@armourinfosec /]# sh

Reserved Bourne shell variables

Variable nameDefinition
CDPATHA colon-separated list of directories used as a search path for thecdbuilt-in command.
HOMEThe current user’s home directory; the default for thecdbuilt-in. The value of this variable is also used by tilde expansion.
IFSA list of characters that separate fields; used when the shell splits words as part of expansion.
MAILIf this parameter is set to a file name and the MAILPATHvariable is not set, Bash informs the user of the arrival of mail in the specified file.
MAILPATHA colon-separated list of file names which the shell periodically checks for new mail.
OPTARGThe value of the last option argument processed by thegetoptsbuilt-in.
OPTINDThe index of the last option argument processed by thegetoptsbuilt-in.
PATHA colon-separated list of directories in which the shell looks for commands.
PS1The primary prompt string. The default value is “‘\s-\v\$ ‘”.
PS2The secondary prompt string. The default value is “‘> ‘”.


Bash reserved variables

Variable nameDefinition
auto_resumeThis variable controls how the shell interacts with the user and job control.
BASHThe full pathname used to execute the current instance of Bash.
BASH_ENVIf this variable is set when Bash is invoked to execute a shell script, its value is expanded and used as the name of a startup file to read before executing the script.
BASH_VERSIONThe version number of the current instance of Bash.
BASH_VERSINFOA read-only array variable whose members hold version information for this instance of Bash.
COLUMNSUsed by the select built-in to determine the terminal width when printing selection lists. Automatically set upon receipt of a SIGWINCH signal.
COMP_CWORDAn index into ${COMP_WORDS}of the word containing the current cursor position.
COMP_LINEThe current command line.
COMP_POINTThe index of the current cursor position relative to the beginning of the currentCommand.
COMP_WORDSAn array variable consisting of the individual words in the current command line.
COMPREPLYAn array variable from which Bash reads the possible completions generated by a shell function invoked by the programmable completion facility.
DIRSTACKAn array variable containing the current contents of the directory stack.
EUIDThe numeric effective user ID of the current user.
FCEDITThe editor used as a default by the -eoption to the fcbuilt-in command.
FIGNOREA colon-separated list of suffixes to ignore when performing file name completion.
FUNCNAMEThe name of any currently-executing shell function.
GLOBIGNOREA colon-separated list of patterns defining the set of file names to be ignored by filename expansion.
GROUPSAn array variable containing the list of groups of which the current user is amember.
histcharsUp to three characters which control history expansion, quick substitution, andtokenization.
HISTCMDThe history number, or index in the history list, of the current command.
HISTCONTROLDefines whether a command is added to the history file.
HISTFILEThe name of the file to which the command history is saved. The default value is~/.bash_history.
HISTFILESIZEThe maximum number of lines contained in the history file, defaults to 500.
HISTIGNOREA colon-separated list of patterns used to decide which command lines should besaved in the history list.
HISTSIZEThe maximum number of commands to remember on the history list, default is 500.
HOSTFILEContains the name of a file in the same format as /etc/hosts that should be readwhen the shell needs to complete a hostname.
HOSTNAMEThe name of the current host.
HOSTTYPEA string describing the machine Bash is running on.
IGNOREEOFControls the action of the shell on receipt of an EOF character as the sole input.
INPUTRCThe name of the Read line initialization file, overriding the default/etc/inputrc.
LANGUsed to determine the locale category for any category not specifically selected witha variable starting with LC_.
LC_ALLThis variable overrides the value of LAN Gand any other LC_variable specifying alocale category.
LC_COLLATEThis variable determines the collation order used when sorting the results of filename expansion, and determines the behavior of range expressions, equivalence

classes, and collating sequences within file name expansion and pattern matching.

LC_CTYPEThis variable determines the interpretation of characters and the behavior ofcharacter classes within file name expansion and pattern matching.
LC_MESSAGESThis variable determines the locale used to translate double-quoted strings precededby a “$” sign.
LC_NUMERICThis variable determines the locale category used for number formatting.
LINENOThe line number in the script or shell function currently executing.
LINESUsed by the select built-in to determine the column length for printing selectionlists.
MACHTYPEA string that fully describes the system type on which Bash is executing, in thestandard GNU CPU-COMPANY-SYSTEM format.
MAILCHECKHow often (in seconds) that the shell should check for mail in the files specified in the MAILPATH or MAIL variables.
OLDPWDThe previous working directory as set by the cd built-in
OPTERRIf set to the value 1, Bash displays error messages generated by the getopts built-in.
OSTYPEA string describing the operating system Bash is running on.
PIPESTATUSAn array variable containing a list of exit status values from the processes in themost recently executed foreground pipeline (which may contain only a single


POSIXLY_CORRECTIf this variable is in the environment when bash starts, the shell enters POSIXmode.
PPIDThe process ID of the shell’s parent process.
PROMPT_COMMANDIf set, the value is interpreted as a command to execute before the printing of eachprimary prompt (PS1)
PS3The value of this variable is used as the prompt for the select command. Defaults to”‘#? ‘”
PS4The value is the prompt printed before the command line is echoed when the -xoption is set; defaults to “‘+ ‘”.
PWDThe current working directory as set by the cd built-in command.
RANDOMEach time this parameter is referenced, a random integer between 0 and 32767 is generated. Assigning a value to this variable seeds the random number generator.
REPLYThe default variable for the read built-in.
SECONDSThis variable expands to the number of seconds since the shell was started.
SHELLOPTSA colon-separated list of enabled shell options.
SHLVLIncremented by one each time a new instance of Bash is started.
TIMEFORMATThe value of this parameter is used as a format string specifying how the timinginformation for pipelines prefixed with the time reserved word should be displayed.
TMOUTIf set to a value greater than zero, TMOUT is treated as the default timeout for theRead built-in. In an inter ative shell, the value is interpreted as the number of

seconds to wait for input after issuing the primary prompt when the shell is

interactive. Bash terminates after that number of seconds if input does not arrive.

UIDThe numeric, real user ID of the current user.

Leave a comment

WhatsApp us