Header Ads

Shell Scripting-Part II

Language:Shell Script.

As you all remember,we started off with Commands in our previous article(Shell Script- Part I).In this article we will be covering the following :-

1)Unix commands.
2)Important Concepts in The Shell(that will help us in UNIX Shell Programming, will take one by one).

Unix Commands:-

1)cal - It displays the calender of any specific month or a complete year.
Syntax :- cal [[month] year] ---------- here, month and year are optional.
$ cal (Press Enter)

Output :- It displays the current month.
2)date - It displays the system date.
Syntax :- date
$ date (Press Enter)

Output :- Mon Sept 6 12:19:47 IST 2010
3)ls - It displays the list of all filenames in the current directory.
Syntax :- ls
$ ls (Press Enter)

Output :- All the files in the current directory are listed.
Note :- ls has many options.We will be explaining in details with File Management Commands.
4)ps - It displays all the user processes.A process is an instance of a running program.
Syntax :- ps
$ ps (Press Enter)

Output :- Displays all process.
Note :- ps has many options.We will be explaining in details with Process Commands.
5)tput clear -- Clear the screen.Here, clear is an argument for the tput.
Syntax :- tput clear
$ tput clear (Press Enter)

Output:- Screen is cleared.
6)Man - This is a help command.
Syntax :- man
$ man ls (Press Enter)

Output :- Explains you about the ls command.
7)tty :- To know your terminal
$ tty (Press Enter)

Output :- /dev/pts/10
8) who :- It displays all the user's information who are logged in to the system at that point of time.
$ who (press enter)

Output :- Displays information about user.
Note :- All unix commands should be in small letters. For example if u write LS instead of ls it will not accept and will throw an error.(command not found error).
I have written some of the frequently used commands. We will be describing them when we take up Unix Commands as a topic.

Important concepts in shell :-

a) Shell variable :- The variables that control the OS are called system variables or Shell Variables.

To know which are shell variable, use the command set.
$ set (Press Enter)
SHELL=/user/bin/bash -------------------------------------------------"Tells user which shell one is using."

TERM=xterm -------------------------------------------------"the terminal Type."

The above variables are mostly found in most of the shell.They are builtin variable for shell and are always in uppercase,inorder to distinguish between the commands.

One can display the contains of the Shell variable by using :-
1) $ echo $
for example :- $ echo $PATH (press enter)
Output :- /bin:/usr/bin:/usr/local/bin:/usr/ccs/bin:/usr/local/java/bin:.

Thus,Shell searches in the above order if an user types in any command in the terminal.These are termed as external commands as ls,cat. Internal commands are shells built in commands and shell never searches them in the above directory,though it might be present,for example cd and echo.

Conclusion :- Going forward we will be discussing some of the other important concepts of the shell and more of UNIX commands.

References :-
1)Third Edition, UNIX concepts and applications By Sumitabh Das.
3) Shell Programming,Yesvant Kanetkar

Powered by Blogger.