Showing posts with label Shell. Show all posts
Showing posts with label Shell. Show all posts

Special Shell Variables - Useful for Scripting

Below are the special shell variables. These are important to know for everyone, especially who is willing to learn shell scripting. Hope the list helps.

Name
Description
$1 - $9
These variables are referring the parameters passed to command or script. $1 refers to the first argument and $2 refers second and so on.
$0
The name of the command or script currently being executed.
$#
The number of arguments passed to the command/script or invocation of the shell.
$?                     
The exit status of the last command executed is given as a decimal string.  When a command completes successfully, it returns the exit status of 0 (zero), otherwise it returns a non-zero exit status.
$$
The process number of the currently executing command or script. - Useful for including in filenames, to make them unique.
$!
The process ID of the last command runs in the background.
$-
The current options supplied to the command or script.
$*
A string containing all the arguments passed to the command/script or shell, starting at $1. When quoted, "$*" is a single word, comprising all the arguments to the shell, joined together with spaces. For example ‘a b' c becomes "a b c".
$@
Same as above, except when quoted. When quoted, "$@" is identical to the arguments received by the shell, the resulting list of words completely match what was given to the shell. For example '1 2' 3 becomes "1 2" "3"

Apart from these, there are some standard variables which are set through .profile or .bashrc. Try "env" command to view all of them.

Different types of shell in UNIX and Linux


Unix Shell
A shell is  command interpreter between user and Unix kernel as well as provides a strong scripting language in UNIX
Following are the different types of Unix shells:
B shell - /bin/sh – This is the default Unix shell for many Unix operating systems .
Bourne shell was written by S. R. Bourne and its more emphasis is to use it as a scripting language rather than an interactive shell .
Some of the features are :
Provided support for environment variables using parameters and exportable variables.
Redirection of program output and error .
Command substitution using back quotes: `command`.
embed a file/commands using input redirector <<
“for ~ do ~ done” loops
“case ~ in ~ esac” for selecting and responding to a data value.
C-shell /bin/csh was designed to provide the interactive features lacking in b shell such as job control and aliasing .
K shell /bin/ksh – was created by David Korn and has features of both B shell and C shell along with some additional features .
Bash – the Bourne again shell was developed by GNU project .It is based on B shell language and has features of C and K shells.
tcsh is the default shell of FreeBSD and its descendants. Essentially it is C shell with programmable command line completion, command-line editing, and a few other features.
Zsh is a shell designed for interactive use and it has many of the useful features of bash, ksh, and tcsh along with many new features.
Unix Shell configuration files :

b shell
—————————————————–
shell prompt : $
executable file : /bin/sh
Read on interactive/non interactive login to bash
/etc/profile
~/.profile

bash shell
—————————————————–
shell prompt : $
executable file : /bin/bash
Read on interactive/non interactive login to bash
/etc/profile
~/.profile
~/.bash_profile
~/.bash_login
Always read on invoking bash
~/.bashrc
/etc/profile login login login
~/.profile login login

csh shell
——————————————————
shell prompt : %
executable file : /bin/csh
Read on csh shell invocation .
/etc/csh.cshrc
~/.cshrc
Read on interactive/non interactive login to tcsh shell
/etc/.login
~/.login
~/.logout
/etc/csh.login

ksh
—————————————————–
shell prompt : $
executable file : /bin/ksh
Read on interactive/non interactive login to bash
/etc/profile
~/.profile

tcsh shell
——————————————————
shell prompt : &
executable file : /bin/tcsh
Read on tcsh shell invocation .
~/.tcshrc
/etc/csh.cshrc
~/.cshrc
Read on interactive/non interactive login to tcsh shell
/etc/.login
~/.login
~/.logout
/etc/csh.login

zsh
—————————————————–
shell prompt : $
executable file : zsh
Configuration files :
Always read on invoking zsh
~/.zshenv always
/etc/zshenv always
only read on interactive login to zsh.
~/.zshrc
/etc/zshrc
Read on interactive/non interactive login to zsh
/etc/zprofile login
/etc/zlogin login
/etc/zlogout login
/.zprofile login
~/.zlogin login
~/.zlogout login


Tech Tip: Move your scripting/coding environment to the cloud by accessing your virtual workstations or virtual servers with 24x7 live support from CloudDesktopOnline.com. For other advanced cloud solutions and products visit www.Apps4Rent.com.