Friday, July 26, 2013

SHELL CUSTOMIZATION



SETTING ENVIRONMENT (BASH)

.bash_profile:  This file contains the commands that define the basic environment for the user
                        login account. This file is read and executed each time the user logs in.

.bash_logout:    This file is read and executed every time a login shell exits.

.bashrc:            If we start up a new shell (sub shell) by typing bash on the command line, it attempts to read commands from the file .bashrc. This allows the flexibility of separating the startup commands needed at the login time from those we might need when we run a sub shell.

Debugging a shell program:

set –n               do not run commands; check for syntax errors only

set –v               echo commands before running them

set –x               echo commands after command-line processing

Processes and Jobs:

Unix gives all processes numbers called PIDs. A job number is assigned by the shell not by the operating system. Job nos. refer to the background processes that are currently running under your shell, whereas pids refer to all processes running on all computers. A job basically refers to a command line that was invoked from the shell.

$ ps                              list all processes on the current terminal
$ ps –a                         lists all processes on all terminals

$ jobs                           to list the current list of jobs

$fg                               to bring a background job to foreground

$bg                              to bring a foreground job to background


$ kill %1                        to kill a job with job no. 1
$ kill –KILL  %1 sure kill for the job
$ kill -9 PID                   sure kill for the process

Signals:
A signal is a message that one process sends to another when some abnormal even takes place or when it wants the other process to do something.
Ex: control C

Trap:
We can trap specific signals and process them in their own way.
trap command sig1 sig2

ex:

trap “echo you have hit control C or control Z ’ INT TERM
while true
do
            sleep 60
done

if we give null string as the command argument to trap, then the shell will ignore that signal

Export:
By default, the values stored in shell variables are local to the shell and are not passed on to a child shell. However, with export command these variables can be made global.

Exec:
Overwrites the code of the program with the code of new program.

Eval:
Eval evaluates twice or parses twice

I/O Redirectors:
>, <, >>

Make:
$ vi makefile
main:    sub1.o sub2.o sub3.o
            cc –o main.c sub1.o sub2.o sub3.o –lm

sub1.o: sub1.c
            cc –c sub1.c
sub2.o : sub2.c
            cc –c sub2.c
sub3.o: sub3.c
            cc –c sub3.c

Ar:
Archives the files
-r          adds a file
-q         appends a file at the end of the archive

-x         extracts a file from the archive

-d         deletes a file from the archive

-t          gives table of contents of the archive

-v         verbose option

$ ar –rv lib.a lib1.o lib2.o


No comments:

Post a Comment