Unix Basics: TIBCO Software Inc
Unix Basics: TIBCO Software Inc
Unix Basics: TIBCO Software Inc
This document (including, without limitation, any product roadmap or statement of direction data) illustrates the planned testing, release and availability dates for TIBCO products and services. This document is provided for informational purposes only and its contents are subject to change
without notice. TIBCO makes no warranties, express or implied, in or relating to this document or any information in it, including, without limitation, that this document, or any information in it, is error-free or meets any conditions of merchantability or fitness for a particular purpose. This
document may not be reproduced or transmitted in any form or by any means without our prior written permission.
CONTENTS
Introduction
Unix File System
Basic Commands
Introduction
A shell is a program that takes commands typed by the
user and calls the operating system to run those
Commands
Shell script is a list of Commands stored in executable
file
Introduction
My First Script
#!/usr/bin/ksh
## This is a comment
echo " Hello World"
echo " today the date is `date`"
echo " Bye for now"
exit 0
Basic commands
Basic commands
Basic Commands
Basic Commands
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
sort n
Sort t | k2 filename
(sort -k 2,2 infile) sorts the contents of infile with the second field as the sort key
-o option is used to output result to a diff file
find /opt/scripts/prod -ctime +100 \( -name "*.log" -o -name "*.msg" \) -exec rm {} \; -print
grep "/bin/bash" /etc/passwd
grep "[hH][aA][Mm]" /etc/passwd
Grep c abc Filename
Grep v abc filename
cut -d |' -f 2-7
cut -c 1-5 a.dat
date1=`date "+%Y%m%d"`
date2=`date "+%Y%m%d%H%M%S"`
date3=`date "+%Y-%m-%d"`
date4=`date "+%A"`
date5=`date "+a"`
Record_count=`wc -l $file_name | tr -s ' ' | cut -d' ' -f2`
ls filename* |cut -c 1-10
Value=`expr $count+10`
Value=`expr string _numeral`
value=`expr $some_count \* 100 / $devider_count`
grep Command
The grep utility is used to search for generalized regular expressions occurring in Unix files
Syntax
grep [options] regexp [file[s]]
Common Options
-i ignore case
-c report only a count of the number of lines containing matches, not the
matches themselves
-v invert the search, displaying only lines that do not match
-n display the line number along with the line on which a match was found
-s work silently, reporting only the final status:
0, for match(es) found
1, for no matches
2, for errors
-l list filenames, but not lines, in which matches were found
grep Command
cat num.list
1 15 fifteen
2 14 fourteen
3 13 thirteen
4 12 twelve
5 11 eleven
6 10 ten
7 9 nine
8 8 eight
9 7 seven
10 6 six
11 5 five
12 4 four
13 3 three
14 2 two
15 1 one
grep Command
o
o
o
o
o
o
o
o
Wild Cards
o Wildcards are the shell's way of abbreviating filenames
o A number of characters are interpreted by the Unix shell
before any other action takes place. These characters
are known as wildcard characters. Usually these
characters are used in place of filenames or directory
names
Regular Expression
o A regular expression is a set of characters that specify a
pattern
o Regular expressions are used when you want to search
for specify lines of text containing a particular pattern
VARIABLE
o A variable is a character string to which we assign a
value. The value assigned could be a number, text,
filename, device, or any other type of data
o A variable is nothing more than a pointer to the actual
data. The shell enables you to create, assign, and delete
variables.
o The name of a variable can contain only letters ( a to z or
A to Z), numbers ( 0 to 9) or the underscore character
( _).
Vname=v_value
Vname=v_value$Vname
Vname= my name is $Vname
Vname=`any regular unix command`
Vname=`expr v_value`
Vname=`expr $a + $b`
Can be declared in a parameter file outside the Program
o
o
o
o
expr 79 \* 45
In the above example \* is a literal asterisk, not a
filename wildcard.
echo Hey! What's next? Mike's #1 friend has $$
echo "Hey! What's next? Mike's #1 friend has $$."
Special Character
o Any Character which has a meaning beyond its literal
meaning is called as Special characters
o #,?,* , >>,> ,/ etc are all special characters
o Back slash (\) is used to disable the special meaning of
special character and instead it will be treated as a literal
text character
Command Substitution
o Executing the Command and assign the output to a
variable
o Use back quotes(`) for Command substitution
o V_date=`date`
o lineCount=`wc -l $fileName | cut -c1-8`
I/O Redirection
o Most of the Commands take input from STDIN , Output the result to
STDOUT and output the errors To STD ERR
o STDIN is the standard input device(default ) and normally from the
keyboard, also it is designated as 0
o STDOUT is the standard output device (default) and normally it is the
monitor and is designated as 1
o STDERR is the Standard error output device (default) and normally it is
the monitor and is designated as 2
o < is used as input Redirection
o > is used as output Redirection
o >> is used to Append the Existing output file
o 2>/dev/null (Garbage Collector)
PIPES
o Pipes (|) are used to pass the output of one command , as input to
the other command
o command1 | command2
o Record_count=`wc -l Filename | tr -s ' ' | cut -d' ' -f2`
Logical Operators
o Logical Operators evaluate to True or False
if [ -f Filename -a -r Filename ]
then
echo " The File is readable"
else
echo " The File is not Readable "
fi
Relational Operators
o Relational allow you to make comparisons between two
expressions.
Arithmetic Operators
vi math.sh
#!/usr/bin/ksh
count=5
count=`expr $count + 1`
echo $count
If-then -else
if-then-else
if [ expr ] then
command-set-1
else
command-set-2
fi
If-then-else if
if [ expr ] then
command-set-1
elif [ expr]
command-set-2
else
Command-set 3
if