Shell scripting for beginners
Topic to be covered:
What is Shell scripting?
Type of shell
File permissions
What is Shell scripting?
Shells are how command-line interfaces are implemented in Linux/Unix. It becomes an interpreter between kernel and user and interprets different commands given and it has various features and a user can choose shell accordingly to their need.The shell is simply an application running on top of the kernel and provides a powerful interface to the system.
Types of shell:-
sh
: Bourne Shell
Developed by Stephen Bourne at AT&T Bell Labs
csh
: C Shell
Developed by Bill Joy at University of California, Berkeley
ksh
: Korn Shell
Developed by David Korn at AT&T Bell Labs backward-compatible with the Bourne shell and includes many features of the C shell
bash
: Bourne Again Shell
Developed by Brian Fox for the GNU Project as a free software replacement for the Bourne shell (sh). Default Shell on Linux and Mac OSX The name is also descriptive of what it did, bashing together the features of sh, csh and ksh
tcsh
: TENEX C Shell
Developed by Ken Greer at Carnegie Mellon University . It is essentially the C shell with programmable command line completion, command-line editing, and a few other features.
File permissions
In *NIX OS’s, you have three types of file permissions :-
1. read (r)
2. write (w)
3. execute (x)
Types of user:-
1. user
2. group
3. world i.e. everyone else who has access to the system
Let us understand this with the help of an example
drwxr-xr-x
The first character signifies the type of the file.
\=> d for directory
\=> - for normal file
--The next three characters of first triad signifies what the owner can do
--The second triad signifies what group member can do
--The third triad signifies what everyone else can do
-Read carries a weight of 4
-Write carries a weight of 2
-Execute carries a weight of 1
The weights are added to give a value of 7 (rwx), 6(rw), 5(rx) or 3(wx) permissions.
-chmod is a *NIX command to change permissions on a file
-To give user rwx, group rx and world x permission, the command is
chmod 751 filename
-Instead of using numerical permissions you can also use symbolic mode
-u/g/o or a user/group/world or all i.e. ugo
-r/w/x read/write/execute
\=> Give everyone execute permission:
chmod a+x hello.sh
chmod ugo+x hello.sh
Remove group and world read & write permission:
chmod go-rw hello.sh
Next blog we will talk about scripting language.