Introduction to Unix (CA263) Command File By Tariq Ibn Aziz.

Slides:



Advertisements
Similar presentations
CS 497C – Introduction to UNIX Lecture 26: - The Process Chin-Chih Chang
Advertisements

CS 497C – Introduction to UNIX Lecture 22: - The Shell Chin-Chih Chang
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
Compunet Corporation Introduction to Unix (CA263) More on Parameters By Tariq Ibn Aziz Dammam Community College.
Introduction to Perl Learning Objectives: 1. To introduce the features provided by Perl 2. To learn the basic Syntax & simple Input/Output control in Perl.
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
Introduction to Perl Software Tools. Slide 2 Introduction to Perl l Perl is a scripting language that makes manipulation of text, files, and processes.
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015.
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Shell Programming 1. Understanding Unix shell programming language: A. It has features of high-level languages. B. Convenient to do the programming. C.
QUOTATION This chapter teaches you about a unique feature of the shell programming language: the way it interprets quote characters. Basically, the shell.
Introduction to Linux and Shell Scripting Jacob Chan.
Shell Script Examples.
2 $ command Command Line Options ls –a –l hello hi Command Arguments.
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
CHAPTER 1 UNIX FOR NONPROGRAMMERS By U ğ ur Halıcı.
1 Lecture 2 Working with Files and Directories COP 3344 Introduction to UNIX.
1 Operating Systems Lecture 3 Shell Scripts. 2 Shell Programming 1.Shell scripts must be marked as executable: chmod a+x myScript 2. Use # to start a.
Writing Shell Scripts ─ part 1 CSE 2031 Fall September 2015.
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
Unix Shells Based on Glass & Abels’ Book CS240 Computer Science II.
An Introduction to Unix Shell Scripting
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Introduction to Linux OS (IV) AUBG ICoSCIS Team Prof. Volin Karagiozov March, 09 – 10, 2013 SWU, Blagoevgrad.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Scripting Languages Course 2 Diana Trandab ă ț Master in Computational Linguistics - 1 st year
Shell Programming Any command or a sequence of UNIX commands stored in a text file is called a shell program. It is common to call this file a command.
CS465 - UNIX The Bourne Shell.
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
LINUX programming 1. INDEX UNIT-III PPT SLIDES Srl. No. Module as per Session planner Lecture No. PPT Slide No. 1.Problem solving approaches in Unix,Using.
Introduction to Unix (CA263) Getting Started By Tariq Ibn Aziz.
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.
Introduction to Unix (CA263) Passing Arguments By Tariq Ibn Aziz Dammam Community College.
Shell Programming Learning Objectives: 1. To understand the some basic utilities of UNIX File 2. To compare UNIX shell and popular shell 3. To learn the.
Introduction to Unix (CA263) Quotes By Tariq Ibn Aziz.
Compunet Corporation Introduction to Unix (CA263) Your Environment By Tariq Ibn Aziz Dammam Community College.
Linux Commands C151 Multi-User Operating Systems.
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
Agenda The Bourne Shell – Part II Special Characters Ambiguous File Reference Variable Names and Values User Created Variables Read-only Variables (Positional.
Compunet Corporation Introduction to Unix (CA263) Round and Round By Tariq Ibn Aziz Dammam Community College.
Lesson 6-Using Utilities to Accomplish Complex Tasks.
Compunet Corporation Introduction to Unix (CA263) Reading Data By Tariq Ibn Aziz Dammam Community College.
Introduction to UNIX (part 2) CSE 2031 Fall March 2016.
File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).
Learning Unix/Linux Based on slides from: Eric Bishop.
Linux Administration Working with the BASH Shell.
 Prepared by: Eng. Maryam Adel Abdel-Hady
Lab 7 Shell Script Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
Tutorial of Unix Command & shell scriptS 5027
Prepared by: Eng. Maryam Adel Abdel-Hady
System Programming and administration CS 308
Some Linux Commands.
Shell Script Assignment 1.
INTRODUCTION TO UNIX: The Shell Command Interface
Tutorial of Unix Command & shell scriptS 5027
Tutorial of Unix Command & shell scriptS 5027
Tutorial of Unix Command & shell scriptS 5027
The Unix File System.
Chapter 3 The UNIX Shells
Introduction to UNIX (part 2)
Introduction to UNIX (part 2)
Introduction to Unix (CA263) Passing Arguments
Presentation transcript:

Introduction to Unix (CA263) Command File By Tariq Ibn Aziz

Objectives In this lecture you will learn –How to write your own commands and how to use shell variables.

Command File A shell program can be typed directly at the terminal –$ who | wc –l Or it can be type into a file and then file can be executed by the shell –$ cat > nu Who | wc -l –$

Execute the Command Type nu at the command name to the shell –$ nu sh: nu: cannot execute –$ You need to add execute permission to this nu script file

chmod Command –Ls –l nu –rw-rw-rw- 1 taziz taziz 12 jul 10 11:42 nu –$ chmod +x nu –rwxrwxrw- 1 taziz taziz 12 jul 10 11:42 nu –$ Now try $ nu 8 $ nu > tally $ cat tally 8

Another Example Suppose you are working on a proposal called sys.caps and followig command sequence is needed every time you want to generate a new copy of a proposal. tbl sys.caps |nroff –mm –Tlp |lp You can save it in a file and give it executable permission and execute script when you need.

Another Example[2] $ cat run tbl sys.caps |nroff –mm –Tlp |lp $ chmod +x run $ run Request id is laser1-15 (standard input)

Another Example[3] $ cat stats date Who | wc –l pwd $ chmod +x stats $ stats Wed Mar 23 11:55:50 ETD /home/aziz/documents/proposals

Another Example[3] You can add some echo command to stats to make the output more informative. $ cat stats echo The current date and time is: date echo echo The number of users on the system is: who | wc –l echo echo Your current working directory is: pwd

Another Example[4] $ stats The current date and time is: Wed Mar 23 11:55:50 ETD 2008 The number of users on the system is: 13 Your current working directory is: /home/aziz/documents/proposals $

Comments –A shell programming cannot be complete without comment statement. –Whenever the shell encounters the special character # at the state of a word, it takes as a comment and ignore the line. # Here is an entire commentary line Who | wc –l# count the number of users # #Test to see if the correct arguments were # supplied $

Comments $ cat stats # # stats – prints: date, number of users # logged on and current directory # echo The current date and time is: date echo echo The number of users on the system is: who | wc –l echo echo Your current working directory is: pwd

Variables Like all programming languages, the shell allow you to store values into variables. A shell variable begins with an alphabetic or underscore (_) character, and followed by zero or more alphanumeric or underscore characters. variable=value

Variables To assign the value 1 to the shell variable count count=1 To assign the value /home/aziz/bin to the shell variable my_bin my_bin=/home/aziz/bin

Displaying the value of Variables The echo command is used to display the value that is stored inside a shell variable echo $variable The $ is a special character to the shell. If a valid variable name follows the $, then shell substitute the value stored inside the variable. $ echo $count 1 $

Displaying the value of Variables You can have the value of more than one variable substituted at a time. $ echo $my_bin /home/aziz/bin $ echo $my_bin $count /home/aziz/bin 1 $

Use of Variables value The value of variables can be used anywhere on the command line. $ ls $my_bin mon nu textx $ pwd /home/aziz/documents/memos $ cd $my_bin $ pwd /home/aziz/bin

Use of Variables value [2] $ number=99 $ echo There are $number pens There are 99 pens

Variables Example $ cat names Ziad Amir Salem Khalid $ command=sort $ $command names Amir Khalid Salem Ziad $ command=wc $ option=-l $ file=names $ command $option $file 7 names

Variables Example[2] $ value1=10 $ value2=value1 $ echo $value2 value1 $ value1=10 $ value2=$value1 $ echo $value2 10

The Null Value Display the value of a variable that was never assigned $ echo $nosuch $ You don’t get an error message $ echo :$nosuch: :: $ A variable that contains no value is said to contain the null value

File Name Substitution and Variable Here is a puzzle for you $ x=* $ Will the shell store character * into variable x, or will it store the names of all files in your current directory $ x=* $ echo $x Addresses into names nu numbers stat phonebook $

File Name Substitution and Variable Was the list of files stored into the variable x when $ echo $x was executed?

File Name Substitution and Variable Shell does not perform file name substitution when assigning values to variables. Therefore, x=* Assigns the single character * to x. This means shell did the file substitution when executing the echo command

File Name Substitution and Variable $echo $x was executed as follows: 1.The shell scanned the line, substituting * as the value of x 2.The shell then rescanned the line, encountered * and then substituted the name of the files in the current directory. 3.The shell then initiated execution of echo passing it the file name as arguments

The ${Variable} Construct Suppose name of file is store in a variable filename. If you want to rename a file so that the new name was same as old, except with an X added to the end $mv $filename $filenameX The shell thinks that filenameX is the full name of variable because it is a valid variable name. To avoid this problem use curly braces{} $mv $filename ${filename}X