UNIX Programming Laboratory. Subject Code: 10MCA17

Size: px
Start display at page:

Download "UNIX Programming Laboratory. Subject Code: 10MCA17"

Transcription

1 UNIX Programming Laboratory Subject Code:

2 1. a. Write a non-recursive shell script which accepts any number of arguments and prints them in the reverse order (For example, if the script is named rags, executing args A B C should produce C B A on the standard output). if [ $# -eq 0 ] echo "Argument not found" i=`echo $* wc -w` while [ $i -gt 0 ] s=`echo $* cut -d " " -f $i` temp=`echo $temp $s` i=`expr $i - 1` echo "Total number of arguments : $#" echo "Arguments list : $*" echo "Reversed list : $temp" Mr. Shylesh B C 2

3 b. Write a shell script that accepts two le names as arguments, checks if the permissions for these les are identical and if the permissions are identical, output common permissions and otherwise output each le name followed by its permissions. if [ $# -eq 0 ] echo "No arguments" elif [ $# -lt 2 ] echo "Only one argument" f1=`ls -l $1 cut -c '2-10'` f2=`ls -l $2 cut -c '2-10'` if [ "$f1" = "$f2" ] echo "File permission are identical" echo "The permissions are : $f1" echo "File permission are not identical" echo "The permission of rst le is f1 : $f1" echo "The permission of the second le is f2 : $f2" Mr. Shylesh B C 3

4 2. a. Write a shell script that takes a valid directory name as an argument and recursively descend all the subdirectories, nds the maximum length of any le in that hierarchy and writes this maximum value to the standard output. echo "Enter Directory name" read dir if [! -d $dir ] echo "Invalid directory" large=0 for le in `nd $dir -type f` size=`stat -c %s $le` echo "size of $le is $size" if [ $size -gt $large ] large=$size echo "File with Maximum size is $large" Mr. Shylesh B C 4

5 b. Write a shell script that accepts a path name and creates all the components in that path name as directories. For example, if the script is named mpc, the command mpc a/b/c/d should create directories a, a/b, a/b/c, a/b/c/d. if [ $# -eq 0 ] echo "Argument not found" temp=$ifs IFS=/ c=0 for i in $* if [ -d $i ] cd $i mkdir $i c=`expr $c + 1` cd $i IFS=$temp echo "$c directories created" Mr. Shylesh B C 5

6 3. a. Write a shell script which accepts valid log-in names as arguments and prints their corresponding home directories, if no arguments are specied, print a suitable error message. if [ $# -eq 0 ] echo "No arguments" for name in $* if grep $name /etc/passwd >/dev/null echo "Login name:$name" hdir=`grep $name /etc/passwd cut -d":" -f6` echo "Home Directory :$hdir" echo "$name is not valid Login name" Mr. Shylesh B C 6

7 b. Write shell script to implement terminal locking (similar to the lock command). It should prompt the user for a password. After accepting the password entered by the user, it must prompt again for the matching password as conrmation and if match occurs, it must lock the keyword until a matching password is entered again by the user, Note that the script must be written to disregard BREAK, control-d. No time limit need be implemented for the lock duration. stty -echo echo "Enter password : " read pass1 echo "Conrm password :" read pass2 if [ "$pass1" = "$pass2" ] echo "Terminal is locked" trap while true echo "Enter password" read pass3 if [ "$pass3" = "$pass2" ] echo "Terminal Unlocked" stty echo echo "Try again" echo "password not match" stty echo Mr. Shylesh B C 7

8 4. a. Create a script le called le-properties that reads a le name entered and outputs it properties. echo "Enter a le name :" read le if [! -e $le ] echo "File es not." ftype=`ls -l $le cut -c 1` fper=`ls -l $le cut -c 2-10` fowner=`ls -l $le tr -s cut -d " " -f3` fsize=`ls -l $le tr -s cut -d " " -f5` fdate=`ls -l $le tr -s cut -d " " -f6` ftime=`ls -l $le tr -s cut -d " " -f7` fname=`ls -l $le tr -s cut -d " " -f8` echo "The le type is : $ftype" echo "The le permission is : $fper" echo "The le owner is : $fowner" echo "The le size is : $fsize" echo "The le date is : $fdate" echo "The le time is : $ftime" echo "The le name is : $fname" Mr. Shylesh B C 8

9 b. Write a shell script that accept one or more lenames as argument and convert all of them to uppercase, provided they exist in current directory. if [ $# -eq 0 ] echo "No Arguments" for le in $* if [ -e $le ] fname=`echo $le tr [a-z] [A-Z] ` echo "The $le is converted to $fname " echo "The directory $le es not " Mr. Shylesh B C 9

10 5. a. Write a shell script that displays all the links to a le specied as the rst argument to the script. The second argument, which is optional, can be used to specify in which the search is to begin. If this second argument is not present, the search is to begin in current working directory. In either case, the starting directory as well as all its subdirectories at all levels must be searched. The script need not include any error checking. if [ $# -eq 0 ] echo "No arguments" if [ $# -eq 2 ] dir=$2 dir=`pwd` inode=`stat -c %i $1` count=0 for link in `nd $dir -inum $inode` echo $link count=`expr $count + 1` if [ $count -eq 0 ] echo "$1 has no link in the directory $dir" echo "$1 has $count links in the directory $dir" Mr. Shylesh B C 10

11 b. Write a shell script that accepts as lename as argument and display its creation time if le exist and if it es not send output error message. if [ $# -eq 0 ] echo "No Arguments" for le in $* if [ -f $le ] fdate=`ls -l $le tr -s cut -d " " -f6` ftime=`ls -l $le tr -s cut -d " " -f7` echo "$le es not " echo "File modied on $fdate at $ftime" Mr. Shylesh B C 11

12 6. a. Write a shell script to display the calendar for current month with current date replaced by * or ** depending on whether the date has one digit or two digits. dt=`date +%d` cal > f3.lst if [ $dt -lt 10 ] dt=`echo $dt cut -c 2` ln=`sed -n 3,$p f3.lst nl grep "$dt" head -1 cut -f1` ln=`expr $ln + 2` sed $ln's/'$dt'/*/' f3.lst sed 's/'$dt'/**/' f3.lst Mr. Shylesh B C 12

13 b. Write a shell script to nd smallest of three numbers that are read from keyboard. echo "Enter the three numbers : " read a b c if [ $a -lt $b -a $a -lt $c ] echo "$a is smallest." elif [ $b -lt $c ] echo "$b is smallest." echo "$c is smallest." Mr. Shylesh B C 13

14 7. a. Write a shell script using expr command to read in a string and display a suitable message if it es not have at least 10 characters. echo "Enter the string" read str if [ -z str ] echo "Null character" len=`expr "$str" : '.*'` if [ $len -ge 10 ] echo "$str has $len character" echo "$str has less than 10 character" Mr. Shylesh B C 14

15 b. Write a shell script to compute the sum of number passed to it as argument on command line and display the result. if [ $# -eq 0 ] echo "No Arguments" echo "To compute the sum of : $*" num=$1 sum=0 while [ $num -gt 0 ] rem=`expr $num % 10` num=`expr $num / 10` sum=`expr $rem + $sum` echo "The result is $sum" Mr. Shylesh B C 15

16 8. a. Write a shell script that compute gross salary of an employee, accordingly to rule given below. If basic salary is < HRA=10% of basic 7 DA=90% of basic. If basic salary is >=15000 HRA=500 of basic & DA=98% of basic. echo "Enter the basic salary :" read basic if [ $basic -lt ] hra=`expr $basic \* 10 / 100` da=`expr $basic \* 90 / 100` hra=`expr $basic \* 50 / 100` da=`expr $basic \* 98 / 100` gross=`expr $basic + $hra + $da` echo " " echo " SALARY " echo " " echo "Basic salary is $basic" echo "HRA is $hra" echo "DA is $da" echo " " echo "Gross salary is $gross" echo " " Mr. Shylesh B C 16

17 b. Write a shell script that delete all lines containing a specic word in one or more le supplied as argument to it. if [ $# -eq 0 ] echo "No arguments" pattern=$1 shift for fname in $* if [ -f $fname ] echo "Deleting $pattern from $fname" sed '/'$pattern'/d' $fname echo "$fname not found" Mr. Shylesh B C 17

18 9. a. Write a shell script that gets executed displays the message either Good Morning or Good Afternoon or Good Evening depending upon time at which the user logs in. time=`who am I tr -s ' ' cut -d " " -f 4 cut -c 1,2` if [ $time -le 12 ] echo "Good Morning $LOGNAME" elif [ $time -gt 12 -a $time -lt 16 ] echo "Good Afternoon $LOGNAME" echo "Good Evening $LOGNAME" Mr. Shylesh B C 18

19 b. Write a shell script that accept a list of lenames as its argument, count and report occurrence of each word that is present in the rst argument le on other argument les. if [ $# -eq 0 ] echo "No Arguments" elif [ $# -eq 1 ] echo "Only one Arguments" pat=$1 if [! -e $1 ] echo "$1 es not exist" shift for le in $* if [ -e $e ] echo $le for pattern in `cat $pat` echo "$pattern occurs `grep -c "$pattern" $le` times" echo "$le es not exist" Mr. Shylesh B C 19

20 10. a. Write a shell script that determine the period for which a specied user is working on system. if [ $# -eq 0 ] echo "No Arguments" if who grep $1 uhtime=`who grep $1 tr -s ' ' cut -d " " -f4 cut -c 1,2` umtime=`who grep $1 tr -s ' ' cut -d " " -f4 cut -c 4,5` hh=`$uhtime cut -d " " -f1` mm=`$umtime cut -d " " -f1` shtime=`date +%H` smtime=`date +%M` timeh=`expr $shtime $hh` timem=`expr $smtime $mm` echo "System time is $shtime hr and $smtime min" echo "Time in which is working $timeh hr and $timem min" echo "Not Valid login name" Mr. Shylesh B C 20

21 b. Write a shell script that reports the logging in of a specied user within one minute after he/she log in. The script automatically terminate if specied user es not log in during a specied period of time. interval=5 name=$1 who awk '{printf $1}' grep "$name" > /dev/null if test $? = 0 loggedin=true echo "$name logged in" loggedin=false echo "$name not logged in" sleep $interval while true who awk '{printf $1}' grep "$name" > /dev/null if test $? = 0 if loggedin=false loggedin=true echo "$name logged in" if loggedin=true loggedin=false echo "$name not logged in" Mr. Shylesh B C 21

22 11. a. Write a shell script that accepts two integers as its argument and compute the value of rst number raised to the power of second number. x=$1 y=$2 z=$x i=1 if [ $# -eq 0 ] echo "No Arguments" while [ $i -lt $y ] z=`expr $z \* $x` i=`expr $i + 1` echo "Value of 1st number raised to the power of 2nd number $x^$y : $z" Mr. Shylesh B C 22

23 b. Write a shell script that accept the le name, starting and ending line number as an argument and display all the lines between the given line number. if [ $# -eq 0 ] echo "No argument" elif [ $# -eq 1 ] echo "Only one argument" elif [ $# -eq 2 ] echo "only two argument" if [! -e $1 ] echo "File es not exist" sed -n $2','$3'p' $1 Mr. Shylesh B C 23

24 12. a. Write a shell script that folds long lines into 40 columns. Thus any line that exceeds 40 characters must be broken after 40th, a \ is to be appended as the indication of folding and the processing is to be continued with the residue. The input is to be supplied through a text le created by the user. # for the purpose of easy execution we have taken limit as 10 not as 40 i=1 while [ $i le `wc -l < temp` ] x=`tail +$i temp head -1` l=`expr "$x" : ".*"` if [ $l le 10 ] #if the length of the line <=10 send directly to output le echo $x >> temp1 while [ `expr "$x" : ".*" ` -ne 0 ] y=`echo $x cut -c 1-10` echo $y "\\" >> temp1 x=`echo "$x" cut -c 10-` i=`expr $i + 1` Mr. Shylesh B C 24

25 b. Write an awk script that accepts date argument in the form of mm-dd-yy and displays it in the form if day, month, and year. The script should check the validity of the argument and in the case of error, display a suitable message. Mr. Shylesh B C 25

26 13. a. Write an awk script to delete duplicated line from a text le. The order of the original lines must remain unchanged. Mr. Shylesh B C 26

27 b. Write an awk script to nd out total number of books sold in each discipline as well as total book sold using associate array wn table as given below. i. Electrical 34, ii. Mechanical 67, iii. Electrical 80, iv. Computer Science 43, v. Mechanical 65, vi. Civil 198 vii. Computer Science 64 Mr. Shylesh B C 27

28 14. Write an awk script to compute gross salary of an employee accordingly to rule given below. If basic salary is < HRA=15% of basic & DA=45% of basic. If basic salary is >=10000 HRA=20% of basic & DA=50% of basic. Mr. Shylesh B C 28

b. Write a shell script to find smallest of three numbers that are read from keyboard. Page 1 07MCA28 Unix Lab Manual:

b. Write a shell script to find smallest of three numbers that are read from keyboard. Page 1 07MCA28 Unix Lab Manual: R.V.College of Engineering Dept. of MCA 1a. Write a non recursive shell script which accepts any number of arguments and prints them in the reverse order (for example, if the script is named rags, executing

More information

Shell programming. Introduction to Operating Systems

Shell programming. Introduction to Operating Systems Shell programming Introduction to Operating Systems Environment variables Predened variables $* all parameters $# number of parameters $? result of last command $$ process identier $i parameter number

More information

Conditional Control Structures. Dr.T.Logeswari

Conditional Control Structures. Dr.T.Logeswari Conditional Control Structures Dr.T.Logeswari TEST COMMAND test expression Or [ expression ] Syntax Ex: a=5; b=10 test $a eq $b ; echo $? [ $a eq $b] ; echo $? 2 Unix Shell Programming - Forouzan 2 TEST

More information

Name: Tej. D. Shah Subject:CC-304 Linux Uni. Practical programme College :L.J. College Of Computer Application. Questions:

Name: Tej. D. Shah Subject:CC-304 Linux Uni. Practical programme College :L.J. College Of Computer Application. Questions: Name: Tej. D. Shah Subject:CC-304 Linux Uni. Practical programme College :L.J. College Of Computer Application Questions: Q.1 Check the output of the following commands:date, ls, who, cal, ps, wc, cat,

More information

INd_rasN SOME SHELL SCRIPTING PROGRAMS. 1. Write a shell script to check whether the name passed as first argument is the name of a file or directory.

INd_rasN SOME SHELL SCRIPTING PROGRAMS. 1. Write a shell script to check whether the name passed as first argument is the name of a file or directory. 1. Write a shell script to check whether the name passed as rst argument is the name of a le or directory. Ans: #!/bin/bash if [ -f $1 ] echo "$1 is a le" echo "$1 is not a le" 2. Write a shell script

More information

Useful Unix Commands Cheat Sheet

Useful Unix Commands Cheat Sheet Useful Unix Commands Cheat Sheet The Chinese University of Hong Kong SIGSC Training (Fall 2016) FILE AND DIRECTORY pwd Return path to current directory. ls List directories and files here. ls dir List

More information

Bourne Shell Reference

Bourne Shell Reference > Linux Reviews > Beginners: Learn Linux > Bourne Shell Reference Bourne Shell Reference found at Br. David Carlson, O.S.B. pages, cis.stvincent.edu/carlsond/cs330/unix/bshellref - Converted to txt2tags

More information

example: name1=jan name2=mike export name1 In this example, name1 is an environmental variable while name2 is a local variable.

example: name1=jan name2=mike export name1 In this example, name1 is an environmental variable while name2 is a local variable. Bourne Shell Programming Variables - creating and assigning variables Bourne shell use the set and unset to create and assign values to variables or typing the variable name, an equal sign and the value

More information

Linux Shell Script. J. K. Mandal

Linux Shell Script. J. K. Mandal Linux Shell Script J. K. Mandal Professor, Department of Computer Science & Engineering, Faculty of Engineering, Technology & Management University of Kalyani Kalyani, Nadia, West Bengal E-mail: jkmandal@klyuniv.ac.in,

More information

QUESTION BANK ON UNIX & SHELL PROGRAMMING-502 (CORE PAPER-2)

QUESTION BANK ON UNIX & SHELL PROGRAMMING-502 (CORE PAPER-2) BANK ON & SHELL PROGRAMMING-502 (CORE PAPER-2) TOPIC 1: VI-EDITOR MARKS YEAR 1. Explain set command of vi editor 2 2011oct 2. Explain the modes of vi editor. 7 2013mar/ 2013 oct 3. Explain vi editor 5

More information

Unix Scripts and Job Scheduling. Overview. Running a Shell Script

Unix Scripts and Job Scheduling. Overview. Running a Shell Script Unix Scripts and Job Scheduling Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh spring@imap.pitt.edu http://www.sis.pitt.edu/~spring Overview Shell Scripts

More information

Shell Control Structures

Shell Control Structures Shell Control Structures CSE 2031 Fall 2010 27 November 2010 1 Control Structures if else for while case (which) until 2 1 if Statement and test Command Syntax: if condition command(s) elif condition_2

More information

Module # 14 References:

Module # 14 References: Module # 14 References: [1] S. Jain, 100 Shell Programs in Unix. Pinnacle Technology, 2009. [2] M. Garrels, Bash Guide for Beginners (Second Edition). Fultus Corporation, 2010. [3] Isrd, Basics Of Os Unix

More information

Unix Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : December, More documents are freely available at PythonDSP

Unix Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : December, More documents are freely available at PythonDSP Unix Guide Meher Krishna Patel Created on : Octorber, 2017 Last updated : December, 2017 More documents are freely available at PythonDSP Table of contents Table of contents i 1 Unix commands 1 1.1 Unix

More information

CS Unix Tools & Scripting

CS Unix Tools & Scripting Cornell University, Spring 2014 1 February 24, 2014 1 Slides evolved from previous versions by Hussam Abu-Libdeh and David Slater A note on awk for (item in array) The order in which items are returned

More information

Shell Control Structures

Shell Control Structures Shell Control Structures EECS 2031 20 November 2017 1 Control Structures l if else l for l while l case (which) l until 2 1 if Statement and test Command l Syntax: if condition command(s) elif condition_2

More information

Preview. Review. The test, or [, command. Conditions. The test, or [, command (String Comparison) The test, or [, command (String Comparison) 2/5/2019

Preview. Review. The test, or [, command. Conditions. The test, or [, command (String Comparison) The test, or [, command (String Comparison) 2/5/2019 Review Shell Scripts How to make executable How to change mode Shell Syntax Variables Quoting Environment Variables Parameter Variables Preview Conditions The test, or [ Command if statement if--if statement

More information

Shell Programming. Introduction to Linux. Peter Ruprecht Research CU Boulder

Shell Programming. Introduction to Linux. Peter Ruprecht  Research CU Boulder Introduction to Linux Shell Programming Peter Ruprecht peter.ruprecht@colorado.edu www.rc.colorado.edu Downloadable Materials Slides and examples available at https://github.com/researchcomputing/ Final_Tutorials/

More information

Answers to Even-numbered Exercises

Answers to Even-numbered Exercises 11 Answers to Even-numbered Exercises 1. ewrite t propriate actions xists and the user does not have write permission to the le. Verify that the modied script works. 2. The special parameter "$@" is referenced

More information

Lecture 02 The Shell and Shell Scripting

Lecture 02 The Shell and Shell Scripting Lecture 02 The Shell and Shell Scripting In this course, we need to be familiar with the "UNIX shell". We use it, whether bash, csh, tcsh, zsh, or other variants, to start and stop processes, control the

More information

Basic Linux (Bash) Commands

Basic Linux (Bash) Commands Basic Linux (Bash) Commands Hint: Run commands in the emacs shell (emacs -nw, then M-x shell) instead of the terminal. It eases searching for and revising commands and navigating and copying-and-pasting

More information

LOG ON TO LINUX AND LOG OFF

LOG ON TO LINUX AND LOG OFF EXPNO:1A LOG ON TO LINUX AND LOG OFF AIM: To know how to logon to Linux and logoff. PROCEDURE: Logon: To logon to the Linux system, we have to enter the correct username and password details, when asked,

More information

Програмиранев UNIX среда

Програмиранев UNIX среда Програмиранев UNIX среда Използванена команден шел и създаванена скриптове: tcsh, bash, awk, python Shell programming As well as using the shell to run commands you can use its built-in programming language

More information

UNIX COMMANDS AND SHELLS. UNIX Programming 2015 Fall by Euiseong Seo

UNIX COMMANDS AND SHELLS. UNIX Programming 2015 Fall by Euiseong Seo UNIX COMMANDS AND SHELLS UNIX Programming 2015 Fall by Euiseong Seo What is a Shell? A system program that allows a user to execute Shell functions (internal commands) Other programs (external commands)

More information

Cisco IOS Shell. Finding Feature Information. Prerequisites for Cisco IOS.sh. Last Updated: December 14, 2012

Cisco IOS Shell. Finding Feature Information. Prerequisites for Cisco IOS.sh. Last Updated: December 14, 2012 Cisco IOS Shell Last Updated: December 14, 2012 The Cisco IOS Shell (IOS.sh) feature provides shell scripting capability to the Cisco IOS command-lineinterface (CLI) environment. Cisco IOS.sh enhances

More information

PART I : MCS-041. (b) Use head and tail in a pipeline to display lines 25 through 75 of a file? $Head 25 file name $Tail 75 File name

PART I : MCS-041. (b) Use head and tail in a pipeline to display lines 25 through 75 of a file? $Head 25 file name $Tail 75 File name Course Code : MCS-045 Course Title : UNIX an DBMS Lab Assignment Number : MAC(4)/045/Assign/06 PART I : MCS-041 Ques 1 : Write the Unix commands for the following: (a) Use the more command, and a pipeline

More information

Shells and Shell Programming

Shells and Shell Programming Shells and Shell Programming Shells A shell is a command line interpreter that is the interface between the user and the OS. The shell: analyzes each command determines what actions are to be performed

More information

Shell Programming (bash)

Shell Programming (bash) Shell Programming Shell Programming (bash) Commands run from a file in a subshell A great way to automate a repeated sequence of commands. File starts with #!/bin/bash absolute path to the shell program

More information

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs Summer 2010 Department of Computer Science and Engineering York University Toronto June 29, 2010 1 / 36 Table of contents 1 2 3 4 2 / 36 Our goal Our goal is to see how we can use Unix as a tool for developing

More information

Unix as a Platform Exercises. Course Code: OS-01-UNXPLAT

Unix as a Platform Exercises. Course Code: OS-01-UNXPLAT Unix as a Platform Exercises Course Code: OS-01-UNXPLAT Working with Unix 1. Use the on-line manual page to determine the option for cat, which causes nonprintable characters to be displayed. Run the command

More information

EECS2301. Special variables. $* and 3/14/2017. Linux/Unix part 2

EECS2301. Special variables. $* and 3/14/2017. Linux/Unix part 2 Warning: These notes are not complete, it is a Skelton that will be modified/add-to in the class. If you want to us them for studying, either attend the class or get the completed notes from someone who

More information

Command Interpreters. command-line (e.g. Unix shell) On Unix/Linux, bash has become defacto standard shell.

Command Interpreters. command-line (e.g. Unix shell) On Unix/Linux, bash has become defacto standard shell. Command Interpreters A command interpreter is a program that executes other programs. Aim: allow users to execute the commands provided on a computer system. Command interpreters come in two flavours:

More information

ADVANCED LINUX SYSTEM ADMINISTRATION

ADVANCED LINUX SYSTEM ADMINISTRATION Lab Assignment 1 Corresponding to Topic 2, The Command Line L1 Main goals To get used to the command line. To gain basic skills with the system shell. To understand some of the basic tools of system administration.

More information

WRITE COMMANDS USING sed or grep (1 mark each) 2014 oct./nov march/april Commands using grep or egrep. (1 mark each)

WRITE COMMANDS USING sed or grep (1 mark each) 2014 oct./nov march/april Commands using grep or egrep. (1 mark each) WRITE COMMANDS USING sed or grep (1 mark each) 2014 oct./nov. 1. Display two lines starting from 7 th line of file X1. 2. Display all blank lines between line 20 and 30 of file X1. 3. Display lines beginning

More information

Shells and Shell Programming

Shells and Shell Programming Shells and Shell Programming 1 Shells A shell is a command line interpreter that is the interface between the user and the OS. The shell: analyzes each command determines what actions are to be performed

More information

Linux Bash Shell Scripting

Linux Bash Shell Scripting University of Chicago Initiative in Biomedical Informatics Computation Institute Linux Bash Shell Scripting Present by: Mohammad Reza Gerami gerami@ipm.ir Day 2 Outline Support Review of Day 1 exercise

More information

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p. Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p. 2 Conventions Used in This Book p. 2 Introduction to UNIX p. 5 An Overview

More information

Shells & Shell Programming (Part B)

Shells & Shell Programming (Part B) Shells & Shell Programming (Part B) Software Tools EECS2031 Winter 2018 Manos Papagelis Thanks to Karen Reid and Alan J Rosenthal for material in these slides CONTROL STATEMENTS 2 Control Statements Conditional

More information

Bourne Shell Programming Topics Covered

Bourne Shell Programming Topics Covered Bourne Shell Programming Topics Covered Shell variables Using Quotes Arithmetic On Shell Passing Arguments Testing conditions Branching if-else, if-elif, case Looping while, for, until break and continue

More information

5/20/2007. Touring Essential Programs

5/20/2007. Touring Essential Programs Touring Essential Programs Employing fundamental utilities. Managing input and output. Using special characters in the command-line. Managing user environment. Surveying elements of a functioning system.

More information

Shell Programming Overview

Shell Programming Overview Overview Shell programming is a way of taking several command line instructions that you would use in a Unix command prompt and incorporating them into one program. There are many versions of Unix. Some

More information

UNIX Shell Scripts. What Is a Shell? The Bourne Shell. Executable Files. Executable Files: Example. Executable Files (cont.) CSE 2031 Fall 2012

UNIX Shell Scripts. What Is a Shell? The Bourne Shell. Executable Files. Executable Files: Example. Executable Files (cont.) CSE 2031 Fall 2012 What Is a Shell? UNIX Shell Scripts CSE 2031 Fall 2012 A program that interprets your requests to run other programs Most common Unix shells: Bourne shell (sh) C shell (csh - tcsh) Korn shell (ksh) Bourne-again

More information

Shell Script Example. Here is a hello world shell script: $ ls -l -rwxr-xr-x 1 horner 48 Feb 19 11:50 hello* $ cat hello #!/bin/sh

Shell Script Example. Here is a hello world shell script: $ ls -l -rwxr-xr-x 1 horner 48 Feb 19 11:50 hello* $ cat hello #!/bin/sh Shell Programming Shells A shell can be used in one of two ways: A command interpreter, used interactively A programming language, to write shell scripts (your own custom commands) Shell Scripts A shell

More information

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT Unix as a Platform Exercises + Solutions Course Code: OS 01 UNXPLAT Working with Unix Most if not all of these will require some investigation in the man pages. That's the idea, to get them used to looking

More information

Linux & Shell Programming 2014

Linux & Shell Programming 2014 Practical No : 1 Enrollment No: Group : A Practical Problem Write a date command to display date in following format: (Consider current date as 4 th January 2014) 1. dd/mm/yy hh:mm:ss 2. Today's date is:

More information

UNIX shell scripting

UNIX shell scripting UNIX shell scripting EECS 2031 Summer 2014 Przemyslaw Pawluk June 17, 2014 What we will discuss today Introduction Control Structures User Input Homework Table of Contents Introduction Control Structures

More information

The Unix Shell & Shell Scripts

The Unix Shell & Shell Scripts The Unix Shell & Shell Scripts You should do steps 1 to 7 before going to the lab. Use the Linux system you installed in the previous lab. In the lab do step 8, the TA may give you additional exercises

More information

5/8/2012. Creating and Changing Directories Chapter 7

5/8/2012. Creating and Changing Directories Chapter 7 Creating and Changing Directories Chapter 7 Types of files File systems concepts Using directories to create order. Managing files in directories. Using pathnames to manage files in directories. Managing

More information

Shell Programming 1/44

Shell Programming 1/44 Shell Programming 1/44 Why shell programming (aka scripting)? Simplicity: Often work at a higher level than compiled languages (easier access to les and directories) Ease of development: Can code a problem

More information

CS214 Advanced UNIX Lecture 4

CS214 Advanced UNIX Lecture 4 CS214 Advanced UNIX Lecture 4 March 2, 2005 Passing arguments to scripts When you invoke a command like > cat f1 f2 f3 f1, f2, f3 are all arguments you pass to the cat command. Many times in your script

More information

Shell Start-up and Configuration Files

Shell Start-up and Configuration Files ULI101 Week 10 Lesson Overview Shell Start-up and Configuration Files Shell History Alias Statement Shell Variables Introduction to Shell Scripting Positional Parameters echo and read Commands if and test

More information

OPERATING SYSTEMS LAB LAB # 6. I/O Redirection and Shell Programming. Shell Programming( I/O Redirection and if-else Statement)

OPERATING SYSTEMS LAB LAB # 6. I/O Redirection and Shell Programming. Shell Programming( I/O Redirection and if-else Statement) P a g e 1 OPERATING SYSTEMS LAB LAB 6 I/O Redirection and Shell Programming Lab 6 Shell Programming( I/O Redirection and if-else Statement) P a g e 2 Redirection of Standard output/input i.e. Input - Output

More information

While Statement Examples. While Statement (35.15) Until Statement (35.15) Until Statement Example

While Statement Examples. While Statement (35.15) Until Statement (35.15) Until Statement Example While Statement (35.15) General form. The commands in the loop are performed while the condition is true. while condition one-or-more-commands While Statement Examples # process commands until a stop is

More information

St. MARTIN S ENGINEERING COLLEGE Dhulapally,Secunderabad DEPARTMENT OF INFORMATION TECHNOLOGY Academic year

St. MARTIN S ENGINEERING COLLEGE Dhulapally,Secunderabad DEPARTMENT OF INFORMATION TECHNOLOGY Academic year St. MARTIN S ENGINEERING COLLEGE Dhulapally,Secunderabad-000 DEPARTMENT OF INFORMATION TECHNOLOGY Academic year 0-0 QUESTION BANK Course Name : LINUX PROGRAMMING Course Code : A0 Class : III B. Tech I

More information

There are some string operators that can be used in the test statement to perform string comparison.

There are some string operators that can be used in the test statement to perform string comparison. ACS-294- Unix (Winter Term, 26-7) Part II: Shell Programming Page 3 The test also returns a nonzero exit value if there is no argument: test String Operators There are some string operators that can be

More information

On successful completion of the course, the students will be able to attain CO: Experiment linked. 2 to 4. 5 to 8. 9 to 12.

On successful completion of the course, the students will be able to attain CO: Experiment linked. 2 to 4. 5 to 8. 9 to 12. CIE- 25 Marks Government of Karnataka Department of Technical Education Bengaluru Course Title: Linux Lab Scheme (L:T:P) : 0:2:4 Total Contact Hours: 78 Type of Course: Tutorial, Practical s & Student

More information

Assignment clarifications

Assignment clarifications Assignment clarifications How many errors to print? at most 1 per token. Interpretation of white space in { } treat as a valid extension, involving white space characters. Assignment FAQs have been updated.

More information

Vi & Shell Scripting

Vi & Shell Scripting Vi & Shell Scripting Comp-206 : Introduction to Week 3 Joseph Vybihal Computer Science McGill University Announcements Sina Meraji's office hours Trottier 3rd floor open area Tuesday 1:30 2:30 PM Thursday

More information

Lab #12: Shell Scripting

Lab #12: Shell Scripting Lab #12 Page 1 of 11 Lab #12: Shell Scripting Students will familiarize themselves with UNIX shell scripting using basic commands to manipulate the le system. Part A Instructions: This part will be demonstrated

More information

Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename

Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename Basic UNIX Commands BASIC UNIX COMMANDS 1. cat This is used to create a file in unix. $ cat >filename This is also used for displaying contents in a file. $ cat filename 2. ls It displays the list of files

More information

bash, part 3 Chris GauthierDickey

bash, part 3 Chris GauthierDickey bash, part 3 Chris GauthierDickey More redirection As you know, by default we have 3 standard streams: input, output, error How do we redirect more than one stream? This requires an introduction to file

More information

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong Shell Prof. Jinkyu Jeong (Jinkyu@skku.edu) TA -- Minwoo Ahn (minwoo.ahn@csl.skku.edu) TA -- Donghyun Kim (donghyun.kim@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu

More information

SHELL SCRIPT BASIC. UNIX Programming 2014 Fall by Euiseong Seo

SHELL SCRIPT BASIC. UNIX Programming 2014 Fall by Euiseong Seo SHELL SCRIPT BASIC UNIX Programming 2014 Fall by Euiseong Seo Shell Script Interactive shell sequentially executes a series of commands Some tasks are repetitive and automatable They are what programs

More information

COMP 4/6262: Programming UNIX

COMP 4/6262: Programming UNIX COMP 4/6262: Programming UNIX Lecture 12 shells, shell programming: passing arguments, if, debug March 13, 2006 Outline shells shell programming passing arguments (KW Ch.7) exit status if (KW Ch.8) test

More information

Lecture 5. Essential skills for bioinformatics: Unix/Linux

Lecture 5. Essential skills for bioinformatics: Unix/Linux Lecture 5 Essential skills for bioinformatics: Unix/Linux UNIX DATA TOOLS Text processing with awk We have illustrated two ways awk can come in handy: Filtering data using rules that can combine regular

More information

Multiple Choice - 42 Questions - 10 of 20%

Multiple Choice - 42 Questions - 10 of 20% DAT2330 Ian Allen Fall 2004-1- 100 minutes Evaluation: 42 Questions Name: Important Instructions 1. Read all the instructions and both sides of all pages. 2. Manage your time when answering questions on

More information

SASGSUB for Job Workflow and SAS Log Files Piyush Singh, Prasoon Sangwan TATA Consultancy Services Ltd. Indianapolis, IN

SASGSUB for Job Workflow and SAS Log Files Piyush Singh, Prasoon Sangwan TATA Consultancy Services Ltd. Indianapolis, IN SCSUG-2016 SASGSUB for Job Workflow and SAS Log Files Piyush Singh, Prasoon Sangwan TATA Consultancy Services Ltd. Indianapolis, IN ABSTRACT SAS Grid Manager Client Utility (SASGSUB) is one of the key

More information

Shell Programming (ch 10)

Shell Programming (ch 10) Vim Commands vim filename Shell Programming (ch 10) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng Add contents: i/a Back to command mode: ESC Save the file: :w Delete: x Quit: :q 1 2 The order

More information

Module 8 Pipes, Redirection and REGEX

Module 8 Pipes, Redirection and REGEX Module 8 Pipes, Redirection and REGEX Exam Objective 3.2 Searching and Extracting Data from Files Objective Summary Piping and redirection Partial POSIX Command Line and Redirection Command Line Pipes

More information

Practice 5 Batch & Shell Programming

Practice 5 Batch & Shell Programming Computer Programming Practice (2008 Fall) Practice 5 Batch & Shell Programming 2008. 10. 8 Contents Batch & Shell Programming Introduction Comment Variables Functions Quoting Flow control Test operations

More information

SHELL SCRIPT BASIC. UNIX Programming 2015 Fall by Euiseong Seo

SHELL SCRIPT BASIC. UNIX Programming 2015 Fall by Euiseong Seo SHELL SCRIPT BASIC UNIX Programming 2015 Fall by Euiseong Seo Shell Script! Interactive shell sequentially executes a series of commands! Some tasks are repetitive and automatable! They are what programs

More information

CSC209H1S Day Midterm Solutions Winter 2010

CSC209H1S Day Midterm Solutions Winter 2010 Duration: Aids Allowed: 50 minutes 1-8.5x11 sheet Student Number: Last Name: SOLUTION First Name: Instructor: Karen Reid Do not turn this page until you have received the signal to start. (In the meantime,

More information

Consider the following program.

Consider the following program. Consider the following program. #include int do_sth (char *s); main(){ char arr [] = "We are the World"; printf ("%d\n", do_sth(arr)); } int do_sth(char *s) { char *p = s; while ( *s++!= \0 )

More information

FREE OPEN SOURCE SOFTWARE(FOSS)LAB Objectives:

FREE OPEN SOURCE SOFTWARE(FOSS)LAB Objectives: II year-ii Semester T P c 0 3 2 FREE OPEN SOURCE SOFTWARE(FOSS)LAB Objectives: Programs: 1. Session-1 To teach students various unix utilities and shell scripting a)log into the system b)use vi editor

More information

UNIX System Programming Lecture 3: BASH Programming

UNIX System Programming Lecture 3: BASH Programming UNIX System Programming Outline Filesystems Redirection Shell Programming Reference BLP: Chapter 2 BFAQ: Bash FAQ BMAN: Bash man page BPRI: Bash Programming Introduction BABS: Advanced Bash Scripting Guide

More information

Last Time. on the website

Last Time. on the website Last Time on the website Lecture 6 Shell Scripting What is a shell? The user interface to the operating system Functionality: Execute other programs Manage files Manage processes Full programming language

More information

Grep and Shell Programming

Grep and Shell Programming Grep and Shell Programming Comp-206 : Introduction to Software Systems Lecture 7 Alexandre Denault Computer Science McGill University Fall 2006 Teacher's Assistants Michael Hawker Monday, 14h30 to 16h30

More information

CSE II-Sem)

CSE II-Sem) 1. Write a shell script to check whether a particular user has logged in or not. If he has logged in, also check whether he has eligibility to receive a message or not. [KRISHNASAI@localhost exp13]$ vi

More information

Part 1: Basic Commands/U3li3es

Part 1: Basic Commands/U3li3es Final Exam Part 1: Basic Commands/U3li3es May 17 th 3:00~4:00pm S-3-143 Same types of questions as in mid-term 1 2 ls, cat, echo ls -l e.g., regular file or directory, permissions, file size ls -a cat

More information

Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename

Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename Basic UNIX Commands BASIC UNIX COMMANDS 1. cat command This command is used to create a file in unix. $ cat >filename This command is also used for displaying contents in a file. $ cat filename 2. ls command

More information

Assignment 3, Due October 4

Assignment 3, Due October 4 Assignment 3, Due October 4 1 Summary This assignment gives you practice with writing shell scripts. Shell scripting is also known as bash programming. Your shell is bash, and when you write a shell script

More information

DISPLAYING A MESSAGE FOR TRAFFIC SIGNAL

DISPLAYING A MESSAGE FOR TRAFFIC SIGNAL DISPLAYING A MESSAGE FOR TRAFFIC SIGNAL Program: echo enter any color code [ R OR Y OR G ] read color if [ $color = R ] then echo STOP! LEAVE WAY FOR OTHERS elif [ $color = Y ] then echo GET READY YOUR

More information

CS 2505 Computer Organization I Test 1

CS 2505 Computer Organization I Test 1 Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other computing devices may

More information

UNIX 및실습. 13 장보충 bash(2)

UNIX 및실습. 13 장보충 bash(2) UNIX 및실습 13 장보충 bash(2) for 정해진횟수의반복 반목문 (1) for 변수 in 단어목록 명령 ( 들 ) ne [kgu@lily ch13]$ cat forloop.bash # Scriptname: forloop for pal in Tom Dick Harry Joe echo "Hi $pal" ne echo "Out of loop" [kgu@lily

More information

2) clear :- It clears the terminal screen. Syntax :- clear

2) clear :- It clears the terminal screen. Syntax :- clear 1) cal :- Displays a calendar Syntax:- cal [options] [ month ] [year] cal displays a simple calendar. If arguments are not specified, the current month is displayed. In addition to cal, the ncal command

More information

Computer Systems and Architecture

Computer Systems and Architecture Computer Systems and Architecture UNIX Scripting Bart Meyers University of Antwerp August 29, 2012 Outline Basics Conditionals Loops Advanced Exercises Shell scripts Grouping commands into a single file

More information

1. Hello World Bash Shell Script. Last Updated on Wednesday, 13 April :03

1. Hello World Bash Shell Script. Last Updated on Wednesday, 13 April :03 1 of 18 21/10/2554 9:39 Bash scripting Tutorial tar -czf myhome_directory.tar.gz /home/linuxcong Last Updated on Wednesday, 13 April 2011 08:03 Article Index 1. Hello World Bash Shell Script 2. Simple

More information

Basic Unix Command. It is used to see the manual of the various command. It helps in selecting the correct options

Basic Unix Command. It is used to see the manual of the various command. It helps in selecting the correct options Basic Unix Command The Unix command has the following common pattern command_name options argument(s) Here we are trying to give some of the basic unix command in Unix Information Related man It is used

More information

Introduction to Linux Basics Part II. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

Introduction to Linux Basics Part II. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala Introduction to Linux Basics Part II 1 Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala pakala@uga.edu 2 Variables in Shell HOW DOES LINUX WORK? Shell Arithmetic I/O and

More information

EECS2301. Example. Testing 3/22/2017. Linux/Unix Part 3. for SCRIPT in /path/to/scripts/dir/* do if [ -f $SCRIPT -a -x $SCRIPT ] then $SCRIPT fi done

EECS2301. Example. Testing 3/22/2017. Linux/Unix Part 3. for SCRIPT in /path/to/scripts/dir/* do if [ -f $SCRIPT -a -x $SCRIPT ] then $SCRIPT fi done Warning: These notes are not complete, it is a Skelton that will be modified/add-to in the class. If you want to us them for studying, either attend the class or get the completed notes from someone who

More information

COMP2100/2500 Lecture 17: Shell Programming II

COMP2100/2500 Lecture 17: Shell Programming II [ANU] [DCS] [COMP2100/2500] [Description] [Schedule] [Lectures] [Labs] [Homework] [Assignments] [COMP2500] [Assessment] [PSP] [Java] [Reading] [Help] COMP2100/2500 Lecture 17: Shell Programming II Summary

More information

UNIX ASSIGNMENT 1 TYBCA (Sem:V)

UNIX ASSIGNMENT 1 TYBCA (Sem:V) UNIX ASSIGNMENT 1 TYBCA (Sem:V) Given Date: 06-08-2015 1. Explain the difference between the following thru example ln & paste tee & (pipeline) 2. What is the difference between the following commands

More information

A shell can be used in one of two ways:

A shell can be used in one of two ways: Shell Scripting 1 A shell can be used in one of two ways: A command interpreter, used interactively A programming language, to write shell scripts (your own custom commands) 2 If we have a set of commands

More information

Appendix B WORKSHOP. SYS-ED/ Computer Education Techniques, Inc.

Appendix B WORKSHOP. SYS-ED/ Computer Education Techniques, Inc. Appendix B WORKSHOP SYS-ED/ Computer Education Techniques, Inc. 1 Introduction There are no workshops for this chapter. The instructor will provide demonstrations and examples. SYS-ED/COMPUTER EDUCATION

More information

CS 2505 Computer Organization I Test 1

CS 2505 Computer Organization I Test 1 Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other computing devices may

More information

What is Bash Shell Scripting?

What is Bash Shell Scripting? What is Bash Shell Scripting? A shell script is a script written for the shell, or command line interpreter, of an operating system. The shell is often considered a simple domain-specic programming language.

More information

Files and Directories

Files and Directories CSCI 2132: Software Development Files and Directories Norbert Zeh Faculty of Computer Science Dalhousie University Winter 2019 Files and Directories Much of the operation of Unix and programs running on

More information

5/8/2012. Encryption-based Protection. Protection based on Access Permission (Contd) File Security, Setting and Using Permissions Chapter 9

5/8/2012. Encryption-based Protection. Protection based on Access Permission (Contd) File Security, Setting and Using Permissions Chapter 9 File Security, Setting and Using Permissions Chapter 9 To show the three protection and security mechanisms that UNIX provides To describe the types of users of a UNIX file To discuss the basic operations

More information

Shell Programming (Part 2)

Shell Programming (Part 2) i i Systems and Internet Infrastructure Security Institute for Networking and Security Research Department of Computer Science and Engineering Pennsylvania State University, University Park, PA Shell Programming

More information

Unix Introduction to UNIX

Unix Introduction to UNIX Unix Introduction to UNIX Get Started Introduction The UNIX operating system Set of programs that act as a link between the computer and the user. Developed in 1969 by a group of AT&T employees Various

More information