AIM: INTRODUCTION TO LINUX SYSTEM
BASICS OF LINUX SYSTEM:
Linux is one of the most powerful and reliable system available and it can be
altered to meet the needs of its users. Linux is layered operating system. The innermost
layer is the hardware that provides services for the operating system known as kernel
which in turn provides services to the user programs. The user programs are independent
of underlying hardware so they are portable to new systems. Linux is multi-user multi-
tasking operating systems. It has many different highly configurable graphical interfaces.
All networking protocols in use on the internet are native to UNIX or LINUX that means
Linux can network better than any other platforms.
Graphical interface: as for intuitive graphical interface, linux has at least dozen
different, highly configurable graphical interfaces, a free implementation of the X
window system. The most popular window managers at the moment are KDE and
GNOME. These offer the point-and-click , drag-and-drop functionality associated with
other user-friendly environment.
Prompt: if we login as root, the prompt will be machine name: ~# and if we login as
user, the prompt will be machine name:~$. The tilde character(~) represents the home
directory; attached to the end of a filename.
Shell account: There are many shells like bourne ,C , korn etc. each of which has slightly
different ways of working. To find out which kind of shell we have on the system, there
is a command “ echo $SHELL”. This will give /bin/bash that means it is bourne
again(bash) shell.
A shell act as the intermediary between the user and the operating system that interprets
the commands into the operating system can understand.
Common linux commands:
1. man: this command brings up the online Unix manual.
2. Is: lists files.
3. pwd: present working directory.
4. cd : change directory.
5. more : this shows the contents of text files.
6. whereis: lets you find a file.
7. vi: visual editor, an editing program.
8. chmod: change file permissions.
9. rm: delete file.
10. cp: copy file.
11. mv: move file.
12. grep: extracts information from files.
TEXT PROCESSING COMMANDS:
Syntax: grep[option] regexp[file(s)]
grep‘abc’file1 – this command displays the lines of the file containing text ‘abc’.
grep’a[abc]’file1-this command displaysthe lines of file1 containing a followed either by
a,b or c.
grep –c ‘abc’ file1 – this command displays the number of lines of the file1 containing
text ‘abc’.
WRITING SHELL PROGRAMS:
We can write shell programs by creating scripts containing a series of shell commands.
The first line should start with #! Which indicates to the kernel that the script is directly
executable. after immediately follow this with the name of the shell., or program , to
execute, using the full path name.
To set up a bourne shell script the first line would be:
#! /bin/sh
Or for the C shell:
#!/bin/csh –f
Quoting:
We quote strings to control the way the shell interprets any parameters or variable within
the string.
Variables:
There are a number of variables automatically set by the shell when it starts. These shell
variables are:
$# Number of arguments on the command line x
$- Option supplied to the shell x
$? Exit value of the last command executed x
$$ Process number of the current process xx
$! Process number of the last command done in background x
$n Argument on the command line
$0 the name of the current shell or program xx
Function :
The bourne shell has functions, somewhat similar to aliases in the C shell , but allow
more flexibility. A function has form:
Fcn(){command;}
Control Commands:
Conditional if
if condotion1
then
command list if condition1 is true
[elif condition2
then command list if condition 2 is true]
[else
command list if condition1 is false]
Conditional while
while condition
do
command list
[break]
[continue]
done
Test:
Conditional statements are evaluated for true or false values. This is done with the test
operators. If the condition evaluates to true , a zero (TRUE) exit status is set, otherwise a
non-zero (FALSE) exist status is set. if there are no arguments a non-zero exist status is
set.
Syntax:
-option filename
AIM: PROGRAMMING WITH PERL
INTRODUCTION TO PERL:
Perl is an acronym for “practical extraction and report language”.
Perl has powerful text-manipulation functions.
Perl is a preferred language in bioinformatics, because of the following reasons:
1. Perl is excellent for processing text.
2. Perl is excellent for CGI-programming.
3. Perl is easy to learn.
Perl scripts are interpreted not compiled. There is no binary copy of the program lebt
behind. All Perl statements end in semicolon. All program in Perl has psuedocodes and
codes known as Perl script.
PROGRAMMING IN PERL:
Psuedocodes: it is an informal program in which there are no details and formal syntax
isn’t followed. It doesn’t actually run as a program; its purpose is to flesh out an idea of
the overall design of a program in quick and informal way.
Comments : comments are parts of Perl source code that are used as an aid to
understanding what the program does.
Comments starts with a hash symbol and run to the end of the line.
# this is a comment.
Perl script:
A Perl script or program consists of one or more statements. These statements are simply
written in the script in a straight forward fashion.
Print “hello, world”;
Whitespaces is irrelevant.
Print
”hello, world”;
Except inside quoted strings
Print “ hello,
World”;
Only double quotes “interpolate” variables and special characters such as newline (\n);
Print “hello, $name \n”; # works file
Print ‘hello, $name\n’; # prints $name\n literally
Numbers don’t need quotes around them.
Print 42;
Variables:
Perl provide 3 kinds of variables: scalars, arrays, and associative arrays(hashes)
Scalar variable:
either a number or string; Perl does not differentiate between the two, nor does it
differentiate between integers and reals.
$aVar = 4;
$b Var = “a sting of words”;
Array variable:
A one dimensional list of scalars. individual elements within an array are referred to as
scalars and the index is placed in square brackets.
@aList = (2,4,6,8);
@bList = @aList; # creates new array and gives it values of @aList
$aList[0] = 1; # changes the values of first item from 2 to 1
Associative array: a special, 2-D array, ideal for handling attribute/ values pairs. the first
element in each row is a key and the second element is a value associated with that key.
$aAA{“A”}= 1; creates first row of assoc.array
$aAA{“B”}= 2; #creates second row of assoc.array
%bAA = %aAA; # creates new assoc.array and gives it values of %aAA
Operators:
Operators access and changes the values of variables. Perl provide 3 kinds of operators.
1. Scalar operators:
Assignment
$aVar1=0xff;#hex assign. For 255 decimal
$aVar2= 0377; # octal assign. For same thing
Double quote interpolated characters include:
\n newline
\a bell
\\ backslash
\” double quote
\l lowercase next letter
\u uppercase next letter
\L lowercase letters follow
\U uppercase letters follow
\E terminate \L or \E
Operators for numbers
+ plus
- minus
* multiply
/ divide
** exponentiation
% modulus
== equal
!= not equal
< less than
> greater than
<= less than or equal to
>= greater than and equal to
+= binary assignment
-= same, subtraction
*= same, multiplication
++ autoincrement
-- autodecrement
Operators for strings
. concatenate
xn repetition
eq equal
ne not equal
lt less than
gt grater than
le less than or equal to
ge grater than or equal to
chop() # remove last character in string
index($string, $substring) # position of substring in string, zero based;
substr($string,$ start.$ length) # substring
2. Array operator:
Assignment
@aList = (2,4,6,8); #explicit values/
@aList =(1..4): # range of values
@aList = (1,”two”,3,”four”); # mixed values
@aList = (); # empty list
@bList = @aList;