How to print or access value of UDV (User defined variables)

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

Using echo command in shell script

CSCI 211 UNIX Lab. Shell Programming. Dr. Jiang Li. Jiang Li, Ph.D. Department of Computer Science

C Shell Tutorial. Section 1

Lab 3a Using the vi editor

Bash Programming. Student Workbook

Bourne Shell (ch 8) Overview. Bourne Shell. Bourne Shell. Bourne Shell. Bourne Shell. Redirect standard error. Redirect standard error

Operating Systems Lab 1 (Users, Groups, and Security)

Shell programming. Introduction to Operating Systems

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

3/8/2017. Unix/Linux Introduction. In this part, we introduce. What does an OS do? Examples

Shell Script Programming

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

CMPS 12A Introduction to Programming Lab Assignment 7

The Unix Shell & Shell Scripts

LOG ON TO LINUX AND LOG OFF

Unix/Linux Operating System. Introduction to Computational Statistics STAT 598G, Fall 2011

Shell Control Structures

UNIX shell scripting

Shells. A shell is a command line interpreter that is the interface between the user and the OS. The shell:

S E C T I O N O V E R V I E W

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

Shells and Shell Programming

Shells and Shell Programming

Shell Control Structures

Mills HPC Tutorial Series. Linux Basics II

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes

CSCM98 Lab Class #5 Getting familiar with the command line

5/20/2007. Touring Essential Programs

More Linux Shell Scripts

Linux Shell Scripting. Linux System Administration COMP2018 Summer 2017

Bash scripting basics

More Raspian. An editor Configuration files Shell scripts Shell variables System admin

Exercise Sheet 2. (Classifications of Operating Systems)

Assignment clarifications

Computer Systems and Architecture

CS Fundamentals of Programming II Fall Very Basic UNIX

CSE 390a Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

Computer Systems and Architecture

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

EECS2301. Lab 1 Winter 2016

Class 2: Variables and Memory. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

Lab 5a Shell Script Lab 4 Using Arithmetic Operators in shell script

Lab 2: Linux/Unix shell

Working with Basic Linux. Daniel Balagué

Part 1: Basic Commands/U3li3es

1. What statistic did the wc -l command show? (do man wc to get the answer) A. The number of bytes B. The number of lines C. The number of words

APPLIED INFORMATICS Processes. Bash characteristics. Command type. Aliases.

System Programming. Session 6 Shell Scripting

Processes and Shells

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12)

Introduction to Unix CHAPTER 6. File Systems. Permissions

INSE Lab 1 Introduction to UNIX Fall 2017

Expressions and Variables

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

28-Nov CSCI 2132 Software Development Lecture 33: Shell Scripting. 26 Shell Scripting. Faculty of Computer Science, Dalhousie University

Process Management forks, bombs, zombies, and daemons! Lecture 5, Hands-On Unix System Administration DeCal

Linux Tutorial #6. -rw-r csce_user csce_user 20 Jan 4 09:15 list1.txt -rw-r csce_user csce_user 26 Jan 4 09:16 list2.

The Online Unix Manual

Perl and R Scripting for Biologists

Introduction to Linux

Basic Linux (Bash) Commands

BraindumpsIT. BraindumpsIT - IT Certification Company provides Braindumps pdf!

Linux File System and Basic Commands

UNIX Tutorial Five

Examples: Directory pathname: File pathname: /home/username/ics124/assignments/ /home/username/ops224/assignments/assn1.txt

Intro to HPC Exercise

This tutorial will teach you about operators. Operators are symbols that are used to represent an actions used in programming.

Topic 2: More Shell Skills. Sub-Topic 1: Quoting. Sub-Topic 2: Shell Variables. Difference Between Single & Double Quotes

M2PGER FORTRAN programming. General introduction. Virginie DURAND and Jean VIRIEUX 10/13/2013 M2PGER - ALGORITHME SCIENTIFIQUE

Review of Fundamentals

Lab 4: Bash Scripting

Removing files and directories, finding files and directories, controlling programs

I/O and Shell Scripting

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

File system Security (Access Rights)

Today. Review. Unix as an OS case study Intro to Shell Scripting. What is an Operating System? What are its goals? How do we evaluate it?

Introduction: What is Unix?

Sub-Topic 1: Quoting. Topic 2: More Shell Skills. Sub-Topic 2: Shell Variables. Referring to Shell Variables: More

Topic 2: More Shell Skills

Shells & Shell Programming (Part B)

Open up a terminal, make sure you are in your home directory, and run the command.

Linux Bootcamp Fall 2015

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Shell Scripting. With Applications to HPC. Edmund Sumbar Copyright 2007 University of Alberta. All rights reserved

Python Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

Scripting Languages Course 1. Diana Trandabăț

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. Shell Scripts. A shell script contains a sequence of commands in a text file. Shell is an command language interpreter.

Linux 系统介绍 (III) 袁华

Self-test Linux/UNIX fundamentals

Linux environment. Graphical interface X-window + window manager. Text interface terminal + shell

CSE 374: Programming Concepts and Tools. Eric Mullen Spring 2017 Lecture 4: More Shell Scripts

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

Introduction to Unix & Perl Programming 1

Getting started with Hugs on Linux

12.1 UNDERSTANDING UNIX SHELL PROGRAMMING LANGUAGE: AN INTRODUCTION Writing a Simple Script Executing a Script

My Favorite bash Tips and Tricks

Transcription:

LAB 5 How to print or access value of UDV (User defined variables) To print or access UDV use following syntax $variablename Define variable vech and n as follows: $ vech=bus $ n=10 To print contains of variable 'vech' type $ echo $vech It will print 'Bus',To print contains of variable 'n' type command as follows $ echo $n Caution: Do not try $ echo vech, as it will print vech instead its value 'Bus' and $ echo n, as it will print n instead its value '10', You must use $ followed by variable name. Exercise Q.1.How to Define variable x with value 10 and print it on screen. Q.2.How to Define variable xn with value Rani and print it on screen Q.3.How to print sum of two numbers, let's say 6 and 3? Q.4.How to define two variable x=20, y=5 and then to print division of x and y (i.e. x/y) Q.5.Modify above and store division of x and y to variable called z Q.6.Point out error if any in following script $ vi variscript Script to test MY knowledge about variables! myname=vivek myos = TroubleOS myno=5 echo "My name is $myname" echo "My os is $myos" echo "My number is myno, can you see this number"

Shell Arithmetic Use to perform arithmetic operations. expr op1 math-operator op2 Examples: $ expr 1 + 3 $ expr 2-1 $ expr 10 / 2 $ expr 20 % 3 $ expr 10 \* 3 $ echo `expr 6 + 3` Note: expr 20 %3 - Remainder read as 20 mod 3 and remainder is 2. expr 10 \* 3 - Multiplication use \* and not * since its wild card. For the last statement not the following points (1) First, before expr keyword we used ` (back quote) sign not the (single quote i.e. ') sign. Back quote is generally found on the key under tilde (~) on PC keyboard OR to the above of TAB key. (2) Second, expr is also end with ` i.e. back quote. (3) Here expr 6 + 3 is evaluated to 9, then echo command prints 9 as sum (4) Here if you use double quote or single quote, it will NOT work For e.g. $ echo "expr 6 + 3" It will print expr 6 + 3 $ echo 'expr 6 + 3' It will print expr 6 + 3 Example: $ echo "Today is date" Can't print message with today's date. $ echo "Today is `date`". It will print today's date as, Today is Tue Jan...,Can you see that the `date` statement uses back quote?

The read Statement Use to get input (data from user) from keyboard and store (data) to variable. read variable1, variable2,...variablen Following script first ask user, name and then waits to enter name from the user via keyboard. Then user enters name from keyboard (after giving name you have to press ENTER key) and entered name through keyboard is stored (assigned) to variable fname. $ vi sayh Script to read your name from key-board echo "Your first name please:" read fname echo "Hello $fname, Lets be friend!" Run it as follows: $ chmod 755 sayh $./sayh Your first name please: vivek Hello vivek, Lets be friend!

What is Processes Process is kind of program or task carried out by your PC. For e.g. $ ls -lr ls command or a request to list files in a directory and all subdirectory in your current directory - It is a process. Process defined as: "A process is program (command given by user) to perform specific Job. In Linux when you start process, it gives a number to process (called PID or process-id), PID starts from 0 to 65535." Why Process required As You know Linux is multi-user, multitasking Os. It means you can run more than two process simultaneously if you wish. For e.g. To find how many files do you have on your system you may give command like: $ ls / -R wc -l This command will take lot of time to search all files on your system. So you can run such command in Background or simultaneously by giving command like $ ls / -R wc -l & The ampersand (&) at the end of command tells shells start process (ls / -R wc - l) and run it in background takes next command immediately. Process & PID defined as: "An instance of running command is called process and the number printed by shell is called process-id (PID), this PID can be use to refer specific running process." Following tables most commonly used command(s) with process: For this purpose Use this Command Examples* To see currently running process ps $ ps To stop any process by PID i.e. to kill process kill {PID} $ kill 1012 To stop processes by name i.e. to kill process killall {Process-name} $ killall httpd To get information about all running process ps -ag $ ps -ag To stop all process except your shell kill 0 $ kill 0 For background processing (With &, use to put particular command and program in background) linux-command & $ ls / -R wc -l &

To display a tree of processes pstree $ pstree * To run some of this command you need to be root or equivalnt user. NOTE that you can only kill process which are created by yourself. A Administrator can almost kill 95-98% process. But some process can not be killed, such as VDU Process. Exercise: You are working on your Linux workstation (might be learning LSST or some other work like sending mails, typing letter), while doing this work you have started to play MP3 files on your workstation. Regarding this situation, answer the following question: