SlideShare uma empresa Scribd logo
1 de 13
Baixar para ler offline
#Lab1a
echo The arguments are
echo $*
echo "The arguments are in the reverse order";
n=$#
while [ $n -gt 0 ]
do
eval "echo $$n" #by using $ we are hiding special meaning of $
n=`expr $n - 1`
done
#/*user@user-Inspiron-N5050:~$ sh lab1a.sh a b c
#The arguments are
#a b c
#The arguments are in the reverse order
#c
#b
#a
#user@user-Inspiron-N5050:~$ sh lab1a.sh 1 2 3
#The arguments are
#1 2 3
#The arguments are in the reverse order
#3
#2
#1
#user@user-Inspiron-N5050:~$
#"Write a shell script that accepts two file names as arguments, check if the permissions for these
files are identical and if the permission are identical, output common permissions and otherwise
output each file name followed by its permissions."
#lab1b
if [ -e $1 ]
then
if [ -e $2 ]
then
x=`ls -l $1|cut -d " " -f1`
y=`ls -l $2|cut -d " " -f1`
if [ $x = $y ]
then
echo "common permission $x"
else
echo "diffrent permissons"
echo "filename is $1 permisson is $x"
echo "filename is $2 permisson is $y"
fi
else
echo "$2 not existing"
fi
else
echo "$1 not existing"
fi
#mit@mit-desktop:~$ gedit lab1b.sh
#mit@mit-desktop:~$ sh lab1b.sh 1 abc /* here abc is a file that not present in our system */
#abc not existing
#mit@mit-desktop:~$ sh lab1b.sh abc 1 /* here abc is a file that not present in our system */
#abc not existing
#mit@mit-desktop:~$ sh lab1b.sh 1 programme2 /* here programme2 is a file that not present in
our system */
#programme2 not existing
#mit@mit-desktop:~$
#"This programme i.e., lab 2 b is written by Ashok"
#write a shell script that accepts a path name & creates all the components in that path name as
directories.
#For ex, if the script is named mpc, then the command mpc a/b/c/d should create directories a, a/b,
a/b/c, a/b/c/d
echo $1>f1 #echo $1 holds the contents of file f1.
x=`cat f1|tr "/" " "`
for i in $x #$x holds all the command line arguments.
do
mkdir $i
cd $i
done
CONCEPT LAB3A
ADDING A USER
mit@mit-desktop:~$ adduser ashok #if this not work try below command.
mit@mit-desktop:~$ sudo adduser ashok
#this command is used to add user. Here sudo stands
for super user.
DISPLAYS PASSWORD FILE OF THE UNIX SYSTEM
mit@mit-desktop:~$ cat /etc/passwd
#this command is used to password file
of the unix system.
mit:x:1000:1000:mit,,,,:/home/mit:/bin/bash
#mit is user and he as password.
ashok:x:1002:1006:Ashok,,,:/home/ashok:/bin/bash #mit is user and he as password.
UNDERSTANDING GREP COMMAND
mit@mit-desktop:~$ cat > file1
mit ashok mca 1st sem
mit@mit-desktop:~$ grep "1st" file1
mit ashok mca 1st sem
mit@mit-desktop:~$ cat > file2
mitashokmca1stsem
mit@mit-desktop:~$ grep "1st" file2 #grep command is used to search the word "1st" is present or
not.
mitashokmca1stsem
mit@mit-desktop:~$ grep -w "1st" file2 #-w command searches the word iff the contents of the
file separated by spaces.
mit@mit-desktop:~$ grep -w "1st" file1
mit ashok mca 1st sem
mit@mit-desktop:~$ grep -c "1st" file1
1

#-c is used to count the number of occurence of the
given word ex: here 1st is occured for 1 time.

mit@mit-desktop:~$ grep -n "1st" file1 #-n is used to display in which line the word "1st" is
occured
1:mit ashok mca 1st sem
#lab3a
#write a shell scripts which accepts valid login name as arguments and prints corresponding home
directory,if no argument is specified print a sutiable error msg.
if [ $# -ne 0 ]
then
for i in $*
do
grep -w "$i" /etc/passwd>ash1#ash1 is a file if $i is present in a file /etc/passwd, the
line of the contents written in file "ash1" otherwise not.
if [ -s ash1 ]

#-s checks the file size.

then
echo "$i is valid user";

#if the file size is not zero then this statement
get exexuted.

cat ash1 | cut -d ":" -f6
else
echo "$i is not a valid user"; #if the file size is zero, this is executed.
fi
done
else
echo "no arguments are passed";
fi
#mit@mit-desktop:~$ sh ashu.sh mit
#mit is valid user
#/home/mit
#mit@mit-desktop:~$ sh ashu.sh MIT
#MIT is not a valid user
#mit@mit-desktop:~$ sh ashu.sh Mit
#Mit is not a valid user
#mit@mit-desktop:~$ sh ashu.sh ashok
#ashok is valid user
#/home/ashok
#mit@mit-desktop:~$ sh ashu.sh vinay
#vinay is not a valid user
#mit@mit-desktop:~$ sh ashu.sh #command with out any arguments.
#no arguments are passed
#Write a shell script OR Create a shell script file called File properties that read
#file name entered & out put it's permissions.
#LAB4A
x=1
while [ $x -eq 1 ]
do
echo "enter u r choice";
read ch
echo "u r choice is $ch"
case $ch in #$ch contain some value.
1 ) echo "file permission `ls -l $0|cut -d ' ' -f1`";; # -f1 is first fild & $0 is current file
itself .
2 )echo "link info `ls -l $0|cut -d ' ' -f2`";; #-f2 is 2nd field
3 )echo "owner info `ls -l $0|cut -d ' ' -f3`";;
4 )echo "group info `ls -l $0|cut -d ' ' -f4`";;
5 )echo "file size `ls -l $0|cut -d ' ' -f5`";;
6 )echo "date of creation `ls -l $0|cut -d ' ' -f6`";;
7 )echo "time `ls -l $0|cut -d ' ' -f7`";;
8 )echo "file name `ls -l $0|cut -d ' ' -f8`";;
* )echo "invald option"
esac
echo "Do you want to contine yes=1 or not=0";
read x
done
#WAP To Find Smallest Of 3 Numbers.
#lab6b
read a
read b
read c
small=$a
if [ $b -lt $a ]
then
small=$b
fi
if [ $c -lt $b ]
then
small=$c
fi
echo "$small is smallest number among $a $b & $c"
#ashok@ubuntu:~$ sh small.sh
#1
#2
#3
#1 is smallest number among 1 2 & 3
#ashok@ubuntu:~$ sh small.sh
#99
#2
#55
#2 is smallest number among 99 2 & 55
#ashok@ubuntu:~$ sh small.sh
#99
#1058
#-99
#-99 is smallest number among 99 1058 & -99
#ashok@ubuntu:~$
CONCEPT LAB7B
#WAS Script To Understand Argument Variables $0, $1, $2, $3, $* And $#
echo "Programme Name $0"
echo "1st Argument $1"
echo "2nd Argument $2"
echo "3rd Argument $3"
echo "All Arguments $*"
echo "Total No. Of Arguments $#"
#output
#ashok@ubuntu:~$ sh 7a.sh 1 2 3 4
#Programme Name 7a.sh
#1st Argument 1
#2nd Argument 2
#3rd Argument 3
#All Arguments 1 2 3 4
#Total No. Of Arguments 4
#ashok@ubuntu:~$
#Write A Shell Script to Compute The Sum Of Numbers Passed To It As Arguments On Command
Line And Display The Result.
#lab7b
num=$1
sum=0
a=0
while [ $num -ne 0 ]
do
rem=`expr $num % 10`
num=`expr $num / 10`
sum=`expr $sum + $rem`
done
echo "sum of digits is = $sum"
#output
#ashok@ubuntu:~$ sh 7b.sh 123
#sum of digits is = 6
#ashok@ubuntu:~$ sh 7b.sh 123456789
#sum of digits is = 45
#ashok@ubuntu:~$ sh 7b.sh 222222
#sum of digits is = 12
#ashok@ubuntu:~$
#Line1 $1 holds 1st Argument. num holds value of $1
#write a shell script that accept a list of filenames as its arguments, count and report occurence of
each word that is present
#in the first argument file on other argument files.
#lab9b
for pattren in `cat $1`
#file is variable like "i" for ex in lab2b programme.
do
for file in $*
#file is variable like "i" for ex in lab2b programme.
do
if [ $file != $1 ]
then
x=`grep -iow $pattren $file|wc -l`
echo "$file contains the word $pattren $x timesn"
fi
done
done
#mcaexam@mit:~$ sh lab9b.sh l1 l2 l3
#l2 contains the word abc 2 times
#
#l3 contains the word abc 2 times
#
#l2 contains the word abcd 1 times
#
#l3 contains the word abcd 1 times
#
#mcaexam@mit:~$ gedit lab9b.sh
#mcaexam@mit:~$ cat l1
#abc
#abcd
#mcaexam@mit:~$ cat l2
#abc
#abc
#abcd
#mcaexam@mit:~$ cat l3
#abc abc
#abcd
#mcaexam@mit:~$
#Lab5b.sh
if [ $# -lt 1 ]
then
echo "Enter file name as an argument";
else
for i in $*
do
if [ -e $i ]
then
x=`ls -l $i|cut -d " " -f7`
echo "file is $i and creation time is $x";
else
echo "$i doesn't exist";
fi
done
fi
#user@user-Inspiron-N5050:~$ sh lab5b.sh f1
#f1 doesn't exist
#user@user-Inspiron-N5050:~$ sh lab5b.sh lab5b.sh
#file is lab5b.sh and creation time is 18:52
#user@user-Inspiron-N5050:~$
#delete a word
#lab 8b
echo "enter a word"
read word
for i in $*
do
grep -iwv "$word" $i > temp
cat temp > $i
done
#user@user-Inspiron-N5050:~$ cat f1
#Ashok
#Harish
#Prakash
#user@user-Inspiron-N5050:~$ cat f2
#inay
#Ashok
#Mahendra
#user@user-Inspiron-N5050:~$ sh lab8b.sh f1 f2
#enter a word
#Ashok
#user@user-Inspiron-N5050:~$ cat f1
#Harish
#Prakash
#user@user-Inspiron-N5050:~$ cat f2
#inay
#Mahendra
#user@user-Inspiron-N5050:~$
#labb11b.sh
if [ $3 -ge $2 ]
then
n=`cat $1|wc -l`
if [ $n -ge $3 ]
then
x=`expr $3 - 1`
y=`expr $x - $2`
head -$x $1|tail -$y
else
echo "insufficient number of lines";
fi
else
echo "ending line number should be greater than starting line number ";
fi
#user@user-Inspiron-N5050:~$ cat f1
#hari
#ashok
#prasad
#prakash
#mary
#koppal
#udupi
#ubuntu
#unix
#windows
#user@user-Inspiron-N5050:~$ sh labb11b.sh f1 2 6
#prasad
#prakash
#mary
#user@user-Inspiron-N5050:~$
#lab11a.sh
k=$2
if [ $k -lt 0 ]
then
k=`expr $k * -1`
fi
i=$1
j=1
pow=1
while [ $j -le $k ]
do
pow=`expr $pow * $i`
j=`expr $j + 1`
done
if [ $2 -lt 0 ]
then
echo "scale=3;`expr 1/$pow`"|bc
else
echo "$1 to the power of $2 is $pow"
fi

#user@user-Inspiron-N5050:~$ sh lab11a.sh 2 3
#2 to the power of 3 is 8
#user@user-Inspiron-N5050:~$ sh lab11a.sh 2 -3
#.125
#user@user-Inspiron-N5050:~$

Mais conteúdo relacionado

Mais procurados (20)

Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in python
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
 
Java package
Java packageJava package
Java package
 
Java I/O and Object Serialization
Java I/O and Object SerializationJava I/O and Object Serialization
Java I/O and Object Serialization
 
Java Applets
Java AppletsJava Applets
Java Applets
 
Date and Time Module in Python | Edureka
Date and Time Module in Python | EdurekaDate and Time Module in Python | Edureka
Date and Time Module in Python | Edureka
 
Docker by Example - Quiz
Docker by Example - QuizDocker by Example - Quiz
Docker by Example - Quiz
 
Html ppt
Html pptHtml ppt
Html ppt
 
STL in C++
STL in C++STL in C++
STL in C++
 
Html forms
Html formsHtml forms
Html forms
 
A Forgotten HTTP Invisibility Cloak
A Forgotten HTTP Invisibility CloakA Forgotten HTTP Invisibility Cloak
A Forgotten HTTP Invisibility Cloak
 
Lecture_7-Encapsulation in Java.pptx
Lecture_7-Encapsulation in Java.pptxLecture_7-Encapsulation in Java.pptx
Lecture_7-Encapsulation in Java.pptx
 
WiFi practical hacking "Show me the passwords!"
WiFi practical hacking "Show me the passwords!"WiFi practical hacking "Show me the passwords!"
WiFi practical hacking "Show me the passwords!"
 
JAVA DUMP SET.pdf
JAVA DUMP SET.pdfJAVA DUMP SET.pdf
JAVA DUMP SET.pdf
 
Web technology lab manual
Web technology lab manualWeb technology lab manual
Web technology lab manual
 
Html audio video
Html audio videoHtml audio video
Html audio video
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Packages and inbuilt classes of java
Packages and inbuilt classes of javaPackages and inbuilt classes of java
Packages and inbuilt classes of java
 
Packages in java
Packages in javaPackages in java
Packages in java
 

Semelhante a Unix 1st sem lab programs a - VTU Karnataka

bash.quickref.pdf
bash.quickref.pdfbash.quickref.pdf
bash.quickref.pdfGiovaRossi
 
390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.pptmugeshmsd5
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Coming Out Of Your Shell - A Comparison of *Nix Shells
Coming Out Of Your Shell - A Comparison of *Nix ShellsComing Out Of Your Shell - A Comparison of *Nix Shells
Coming Out Of Your Shell - A Comparison of *Nix ShellsKel Cecil
 
Gujrat University bca sem 6SHELL MAIN.pdf
Gujrat University bca sem 6SHELL MAIN.pdfGujrat University bca sem 6SHELL MAIN.pdf
Gujrat University bca sem 6SHELL MAIN.pdfRajeshPatel136226
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell ScriptingRaghu nath
 
Shell Scripts
Shell ScriptsShell Scripts
Shell ScriptsDr.Ravi
 
Mkscript sh
Mkscript shMkscript sh
Mkscript shBen Pope
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationWorkhorse Computing
 
Advanced linux chapter ix-shell script
Advanced linux chapter ix-shell scriptAdvanced linux chapter ix-shell script
Advanced linux chapter ix-shell scriptEliezer Moraes
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Bash shell
Bash shellBash shell
Bash shellxylas121
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingvibrantuser
 

Semelhante a Unix 1st sem lab programs a - VTU Karnataka (20)

bash.quickref.pdf
bash.quickref.pdfbash.quickref.pdf
bash.quickref.pdf
 
390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.ppt
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Coming Out Of Your Shell - A Comparison of *Nix Shells
Coming Out Of Your Shell - A Comparison of *Nix ShellsComing Out Of Your Shell - A Comparison of *Nix Shells
Coming Out Of Your Shell - A Comparison of *Nix Shells
 
Gujrat University bca sem 6SHELL MAIN.pdf
Gujrat University bca sem 6SHELL MAIN.pdfGujrat University bca sem 6SHELL MAIN.pdf
Gujrat University bca sem 6SHELL MAIN.pdf
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell Scripting
 
What is a shell script
What is a shell scriptWhat is a shell script
What is a shell script
 
Shell Scripts
Shell ScriptsShell Scripts
Shell Scripts
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Mkscript sh
Mkscript shMkscript sh
Mkscript sh
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic Interpolation
 
Advanced linux chapter ix-shell script
Advanced linux chapter ix-shell scriptAdvanced linux chapter ix-shell script
Advanced linux chapter ix-shell script
 
Shell programming
Shell programmingShell programming
Shell programming
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Bash shell
Bash shellBash shell
Bash shell
 
First steps in C-Shell
First steps in C-ShellFirst steps in C-Shell
First steps in C-Shell
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scripting
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 

Mais de iCreateWorld

Unix 1st sem lab programs b - VTU Karnataka
Unix 1st sem lab programs b - VTU KarnatakaUnix 1st sem lab programs b - VTU Karnataka
Unix 1st sem lab programs b - VTU KarnatakaiCreateWorld
 
Data structure doubly linked list programs
Data structure doubly linked list programsData structure doubly linked list programs
Data structure doubly linked list programsiCreateWorld
 
Data structure circular list
Data structure circular listData structure circular list
Data structure circular listiCreateWorld
 
Data structure singly linked list programs VTU Exams
Data structure singly linked list programs VTU ExamsData structure singly linked list programs VTU Exams
Data structure singly linked list programs VTU ExamsiCreateWorld
 
Location Tracking of Android Device Based on SMS.
Location Tracking of Android Device Based on SMS.Location Tracking of Android Device Based on SMS.
Location Tracking of Android Device Based on SMS.iCreateWorld
 
1 location tracking of android device based on sms
 1 location tracking of android device based on sms 1 location tracking of android device based on sms
1 location tracking of android device based on smsiCreateWorld
 

Mais de iCreateWorld (6)

Unix 1st sem lab programs b - VTU Karnataka
Unix 1st sem lab programs b - VTU KarnatakaUnix 1st sem lab programs b - VTU Karnataka
Unix 1st sem lab programs b - VTU Karnataka
 
Data structure doubly linked list programs
Data structure doubly linked list programsData structure doubly linked list programs
Data structure doubly linked list programs
 
Data structure circular list
Data structure circular listData structure circular list
Data structure circular list
 
Data structure singly linked list programs VTU Exams
Data structure singly linked list programs VTU ExamsData structure singly linked list programs VTU Exams
Data structure singly linked list programs VTU Exams
 
Location Tracking of Android Device Based on SMS.
Location Tracking of Android Device Based on SMS.Location Tracking of Android Device Based on SMS.
Location Tracking of Android Device Based on SMS.
 
1 location tracking of android device based on sms
 1 location tracking of android device based on sms 1 location tracking of android device based on sms
1 location tracking of android device based on sms
 

Último

Ultra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxUltra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxDr. Asif Anas
 
Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphNetziValdelomar1
 
Benefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationBenefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationMJDuyan
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICESayali Powar
 
What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?TechSoup
 
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfP4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfYu Kanazawa / Osaka University
 
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptxPISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptxEduSkills OECD
 
How to Manage Cross-Selling in Odoo 17 Sales
How to Manage Cross-Selling in Odoo 17 SalesHow to Manage Cross-Selling in Odoo 17 Sales
How to Manage Cross-Selling in Odoo 17 SalesCeline George
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxiammrhaywood
 
Practical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptxPractical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptxKatherine Villaluna
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17Celine George
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxAditiChauhan701637
 
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRADUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRATanmoy Mishra
 
CAULIFLOWER BREEDING 1 Parmar pptx
CAULIFLOWER BREEDING 1 Parmar pptxCAULIFLOWER BREEDING 1 Parmar pptx
CAULIFLOWER BREEDING 1 Parmar pptxSaurabhParmar42
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfMohonDas
 
General views of Histopathology and step
General views of Histopathology and stepGeneral views of Histopathology and step
General views of Histopathology and stepobaje godwin sunday
 
Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...raviapr7
 
How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17Celine George
 
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptxClinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptxraviapr7
 

Último (20)

Ultra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxUltra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptx
 
Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a Paragraph
 
Benefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationBenefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive Education
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICE
 
What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?
 
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfP4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
 
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptxPISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
 
How to Manage Cross-Selling in Odoo 17 Sales
How to Manage Cross-Selling in Odoo 17 SalesHow to Manage Cross-Selling in Odoo 17 Sales
How to Manage Cross-Selling in Odoo 17 Sales
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
 
Practical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptxPractical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptx
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptx
 
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRADUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
 
Prelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quizPrelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quiz
 
CAULIFLOWER BREEDING 1 Parmar pptx
CAULIFLOWER BREEDING 1 Parmar pptxCAULIFLOWER BREEDING 1 Parmar pptx
CAULIFLOWER BREEDING 1 Parmar pptx
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdf
 
General views of Histopathology and step
General views of Histopathology and stepGeneral views of Histopathology and step
General views of Histopathology and step
 
Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...
 
How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17
 
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptxClinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
 

Unix 1st sem lab programs a - VTU Karnataka

  • 1. #Lab1a echo The arguments are echo $* echo "The arguments are in the reverse order"; n=$# while [ $n -gt 0 ] do eval "echo $$n" #by using $ we are hiding special meaning of $ n=`expr $n - 1` done #/*user@user-Inspiron-N5050:~$ sh lab1a.sh a b c #The arguments are #a b c #The arguments are in the reverse order #c #b #a #user@user-Inspiron-N5050:~$ sh lab1a.sh 1 2 3 #The arguments are #1 2 3 #The arguments are in the reverse order #3 #2 #1 #user@user-Inspiron-N5050:~$
  • 2. #"Write a shell script that accepts two file names as arguments, check if the permissions for these files are identical and if the permission are identical, output common permissions and otherwise output each file name followed by its permissions." #lab1b if [ -e $1 ] then if [ -e $2 ] then x=`ls -l $1|cut -d " " -f1` y=`ls -l $2|cut -d " " -f1` if [ $x = $y ] then echo "common permission $x" else echo "diffrent permissons" echo "filename is $1 permisson is $x" echo "filename is $2 permisson is $y" fi else echo "$2 not existing" fi else echo "$1 not existing" fi #mit@mit-desktop:~$ gedit lab1b.sh #mit@mit-desktop:~$ sh lab1b.sh 1 abc /* here abc is a file that not present in our system */ #abc not existing #mit@mit-desktop:~$ sh lab1b.sh abc 1 /* here abc is a file that not present in our system */ #abc not existing #mit@mit-desktop:~$ sh lab1b.sh 1 programme2 /* here programme2 is a file that not present in our system */ #programme2 not existing #mit@mit-desktop:~$
  • 3. #"This programme i.e., lab 2 b is written by Ashok" #write a shell script that accepts a path name & creates all the components in that path name as directories. #For ex, if the script is named mpc, then the command mpc a/b/c/d should create directories a, a/b, a/b/c, a/b/c/d echo $1>f1 #echo $1 holds the contents of file f1. x=`cat f1|tr "/" " "` for i in $x #$x holds all the command line arguments. do mkdir $i cd $i done
  • 4. CONCEPT LAB3A ADDING A USER mit@mit-desktop:~$ adduser ashok #if this not work try below command. mit@mit-desktop:~$ sudo adduser ashok #this command is used to add user. Here sudo stands for super user. DISPLAYS PASSWORD FILE OF THE UNIX SYSTEM mit@mit-desktop:~$ cat /etc/passwd #this command is used to password file of the unix system. mit:x:1000:1000:mit,,,,:/home/mit:/bin/bash #mit is user and he as password. ashok:x:1002:1006:Ashok,,,:/home/ashok:/bin/bash #mit is user and he as password. UNDERSTANDING GREP COMMAND mit@mit-desktop:~$ cat > file1 mit ashok mca 1st sem mit@mit-desktop:~$ grep "1st" file1 mit ashok mca 1st sem mit@mit-desktop:~$ cat > file2 mitashokmca1stsem mit@mit-desktop:~$ grep "1st" file2 #grep command is used to search the word "1st" is present or not. mitashokmca1stsem mit@mit-desktop:~$ grep -w "1st" file2 #-w command searches the word iff the contents of the file separated by spaces. mit@mit-desktop:~$ grep -w "1st" file1 mit ashok mca 1st sem mit@mit-desktop:~$ grep -c "1st" file1 1 #-c is used to count the number of occurence of the given word ex: here 1st is occured for 1 time. mit@mit-desktop:~$ grep -n "1st" file1 #-n is used to display in which line the word "1st" is occured 1:mit ashok mca 1st sem
  • 5. #lab3a #write a shell scripts which accepts valid login name as arguments and prints corresponding home directory,if no argument is specified print a sutiable error msg. if [ $# -ne 0 ] then for i in $* do grep -w "$i" /etc/passwd>ash1#ash1 is a file if $i is present in a file /etc/passwd, the line of the contents written in file "ash1" otherwise not. if [ -s ash1 ] #-s checks the file size. then echo "$i is valid user"; #if the file size is not zero then this statement get exexuted. cat ash1 | cut -d ":" -f6 else echo "$i is not a valid user"; #if the file size is zero, this is executed. fi done else echo "no arguments are passed"; fi #mit@mit-desktop:~$ sh ashu.sh mit #mit is valid user #/home/mit #mit@mit-desktop:~$ sh ashu.sh MIT #MIT is not a valid user #mit@mit-desktop:~$ sh ashu.sh Mit #Mit is not a valid user #mit@mit-desktop:~$ sh ashu.sh ashok #ashok is valid user #/home/ashok #mit@mit-desktop:~$ sh ashu.sh vinay #vinay is not a valid user #mit@mit-desktop:~$ sh ashu.sh #command with out any arguments. #no arguments are passed
  • 6. #Write a shell script OR Create a shell script file called File properties that read #file name entered & out put it's permissions. #LAB4A x=1 while [ $x -eq 1 ] do echo "enter u r choice"; read ch echo "u r choice is $ch" case $ch in #$ch contain some value. 1 ) echo "file permission `ls -l $0|cut -d ' ' -f1`";; # -f1 is first fild & $0 is current file itself . 2 )echo "link info `ls -l $0|cut -d ' ' -f2`";; #-f2 is 2nd field 3 )echo "owner info `ls -l $0|cut -d ' ' -f3`";; 4 )echo "group info `ls -l $0|cut -d ' ' -f4`";; 5 )echo "file size `ls -l $0|cut -d ' ' -f5`";; 6 )echo "date of creation `ls -l $0|cut -d ' ' -f6`";; 7 )echo "time `ls -l $0|cut -d ' ' -f7`";; 8 )echo "file name `ls -l $0|cut -d ' ' -f8`";; * )echo "invald option" esac echo "Do you want to contine yes=1 or not=0"; read x done
  • 7. #WAP To Find Smallest Of 3 Numbers. #lab6b read a read b read c small=$a if [ $b -lt $a ] then small=$b fi if [ $c -lt $b ] then small=$c fi echo "$small is smallest number among $a $b & $c" #ashok@ubuntu:~$ sh small.sh #1 #2 #3 #1 is smallest number among 1 2 & 3 #ashok@ubuntu:~$ sh small.sh #99 #2 #55 #2 is smallest number among 99 2 & 55 #ashok@ubuntu:~$ sh small.sh #99 #1058 #-99 #-99 is smallest number among 99 1058 & -99 #ashok@ubuntu:~$
  • 8. CONCEPT LAB7B #WAS Script To Understand Argument Variables $0, $1, $2, $3, $* And $# echo "Programme Name $0" echo "1st Argument $1" echo "2nd Argument $2" echo "3rd Argument $3" echo "All Arguments $*" echo "Total No. Of Arguments $#" #output #ashok@ubuntu:~$ sh 7a.sh 1 2 3 4 #Programme Name 7a.sh #1st Argument 1 #2nd Argument 2 #3rd Argument 3 #All Arguments 1 2 3 4 #Total No. Of Arguments 4 #ashok@ubuntu:~$ #Write A Shell Script to Compute The Sum Of Numbers Passed To It As Arguments On Command Line And Display The Result. #lab7b num=$1 sum=0 a=0 while [ $num -ne 0 ] do rem=`expr $num % 10` num=`expr $num / 10` sum=`expr $sum + $rem` done echo "sum of digits is = $sum" #output #ashok@ubuntu:~$ sh 7b.sh 123 #sum of digits is = 6 #ashok@ubuntu:~$ sh 7b.sh 123456789 #sum of digits is = 45 #ashok@ubuntu:~$ sh 7b.sh 222222 #sum of digits is = 12 #ashok@ubuntu:~$ #Line1 $1 holds 1st Argument. num holds value of $1
  • 9. #write a shell script that accept a list of filenames as its arguments, count and report occurence of each word that is present #in the first argument file on other argument files. #lab9b for pattren in `cat $1` #file is variable like "i" for ex in lab2b programme. do for file in $* #file is variable like "i" for ex in lab2b programme. do if [ $file != $1 ] then x=`grep -iow $pattren $file|wc -l` echo "$file contains the word $pattren $x timesn" fi done done #mcaexam@mit:~$ sh lab9b.sh l1 l2 l3 #l2 contains the word abc 2 times # #l3 contains the word abc 2 times # #l2 contains the word abcd 1 times # #l3 contains the word abcd 1 times # #mcaexam@mit:~$ gedit lab9b.sh #mcaexam@mit:~$ cat l1 #abc #abcd #mcaexam@mit:~$ cat l2 #abc #abc #abcd #mcaexam@mit:~$ cat l3 #abc abc #abcd #mcaexam@mit:~$
  • 10. #Lab5b.sh if [ $# -lt 1 ] then echo "Enter file name as an argument"; else for i in $* do if [ -e $i ] then x=`ls -l $i|cut -d " " -f7` echo "file is $i and creation time is $x"; else echo "$i doesn't exist"; fi done fi #user@user-Inspiron-N5050:~$ sh lab5b.sh f1 #f1 doesn't exist #user@user-Inspiron-N5050:~$ sh lab5b.sh lab5b.sh #file is lab5b.sh and creation time is 18:52 #user@user-Inspiron-N5050:~$
  • 11. #delete a word #lab 8b echo "enter a word" read word for i in $* do grep -iwv "$word" $i > temp cat temp > $i done #user@user-Inspiron-N5050:~$ cat f1 #Ashok #Harish #Prakash #user@user-Inspiron-N5050:~$ cat f2 #inay #Ashok #Mahendra #user@user-Inspiron-N5050:~$ sh lab8b.sh f1 f2 #enter a word #Ashok #user@user-Inspiron-N5050:~$ cat f1 #Harish #Prakash #user@user-Inspiron-N5050:~$ cat f2 #inay #Mahendra #user@user-Inspiron-N5050:~$
  • 12. #labb11b.sh if [ $3 -ge $2 ] then n=`cat $1|wc -l` if [ $n -ge $3 ] then x=`expr $3 - 1` y=`expr $x - $2` head -$x $1|tail -$y else echo "insufficient number of lines"; fi else echo "ending line number should be greater than starting line number "; fi #user@user-Inspiron-N5050:~$ cat f1 #hari #ashok #prasad #prakash #mary #koppal #udupi #ubuntu #unix #windows #user@user-Inspiron-N5050:~$ sh labb11b.sh f1 2 6 #prasad #prakash #mary #user@user-Inspiron-N5050:~$
  • 13. #lab11a.sh k=$2 if [ $k -lt 0 ] then k=`expr $k * -1` fi i=$1 j=1 pow=1 while [ $j -le $k ] do pow=`expr $pow * $i` j=`expr $j + 1` done if [ $2 -lt 0 ] then echo "scale=3;`expr 1/$pow`"|bc else echo "$1 to the power of $2 is $pow" fi #user@user-Inspiron-N5050:~$ sh lab11a.sh 2 3 #2 to the power of 3 is 8 #user@user-Inspiron-N5050:~$ sh lab11a.sh 2 -3 #.125 #user@user-Inspiron-N5050:~$