Using echo command in shell script

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

Lab 3a Using the vi editor

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

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

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

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

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

Invent Your Own Computer Games with Python

Getting started with Hugs on Linux

Scripting. More Shell Scripts Loops. Adapted from Practical Unix and Programming Hunter College

Review of Fundamentals

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Linux at the Command Line Don Johnson of BU IS&T

Linux Exercise. pwd answer: We call this directory (into which you get when you log in) your home directory.

15-122: Principles of Imperative Computation

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Linux Operating System Environment Computadors Grau en Ciència i Enginyeria de Dades Q2

CSE 351. Introduction & Course Tools

CS CS Tutorial 2 2 Winter 2018

Lecture 1. A. Sahu and S. V. Rao. Indian Institute of Technology Guwahati

Working with Shell Scripting. Daniel Balagué

Exercise 1: Basic Tools

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Shell Script Programming

Introduction to Joker Cyber Infrastructure Architecture Team CIA.NMSU.EDU

Exercise sheet 1 To be corrected in tutorials in the week from 23/10/2017 to 27/10/2017

EE516: Embedded Software Project 1. Setting Up Environment for Projects

Grep and Shell Programming

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Bash Programming. Student Workbook

CS246-Assign01 V1.1: Winter 2013

Using bash. Administrative Shell Scripting COMP2101 Fall 2017

Linux Shell Script. J. K. Mandal

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

CLAS12 Software Tutorial

Introduction to Linux

Exercises. Computer Tech Tom Browder Northwest Florida Linux User Group [nwflug.org]

Lab 6: OS Security for the Internet of Things

Lab 6: OS Security for the Internet of Things

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

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Mauro Ceccanti e Alberto Paoluzzi

Shell scripting and system variables. HORT Lecture 5 Instructor: Kranthi Varala

Compiling C/C++ programs

Introduction: What is Unix?

Lab #12: Shell Scripting

More Linux Shell Scripts

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.

Lec 1 add-on: Linux Intro

Chapter 9. Shell and Kernel

D. Delete the /var/lib/slocate/slocate.db file because it buffers all search results.

Vi & Shell Scripting

Getting started with Hugs on Linux

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Esercitazione Introduzione al linguaggio di shell

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

Introduction to Linux

Traditional Access Permissions

Running Speech Recognition Experiments on XSEDE. Mark Hasegawa-Johnson 1/28/2014

Assume that username is cse. The user s home directory will be /home/cse. You may remember what the relative pathname for users home directory is: ~

Lab 1 : An Introduction to SPIM, the MIPS architecture simulator

CMSC 201 Spring 2017 Lab 01 Hello World

How to Create a NetBeans PHP Project

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.

BIOINFORMATICS POST-DIPLOMA PROGRAM SUBJECT OUTLINE Subject Title: OPERATING SYSTEMS AND PROJECT MANAGEMENT Subject Code: BIF713 Subject Description:

Practical Session 0 Introduction to Linux

ITEC451 Network Design & Analysis Laboratory Guide: Appendix

Introduction to the UNIX command line

INTRODUCTION TO UNIX

Introduction to remote command line Linux. Research Computing Team University of Birmingham

UNIX. The Very 10 Short Howto for beginners. Soon-Hyung Yook. March 27, Soon-Hyung Yook UNIX March 27, / 29

Linux Shell Scripting. Linux System Administration COMP2018 Summer 2017

Network softwarization Lab session 2: OS Virtualization Networking

CISC 220 fall 2011, set 1: Linux basics

24 Writing Your First Script

27-Sep CSCI 2132 Software Development Lab 4: Exploring bash and C Compilation. Faculty of Computer Science, Dalhousie University

CMSC 201 Spring 2018 Lab 01 Hello World

Temple University Computer Science Programming Under the Linux Operating System January 2017

Practical 04: UNIX / LINUX Shell Programming 1

LINUX FUNDAMENTALS. Supported Distributions: Red Hat Enterprise Linux 6 SUSE Linux Enterprise 11 Ubuntu LTS. Recommended Class Length: 5 days

Lab 6 : Introduction to Verilog

Dirty COW Attack Lab

Manual Script Windows Batch If Condition. Syntax >>>CLICK HERE<<<

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group.

Lesson 3 Transcript: Part 2 of 2 Tools & Scripting

MicroEmbedded Technologies, Pune. A user manual for Using the BeagleBone Black with Linux Host.

Introduction to UNIX Command Line

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Introduction to Linux for BlueBEAR. January

A Big Step. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

Lab #8: Introduction to UNIX and GMT

Linux shell & shell scripting - II

Unix Introduction to UNIX

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

Prerequisites: Students should be comfortable with computers. No familiarity with Linux or other Unix operating systems is required.

Lab 4: Bash Scripting

COMS 6100 Class Notes 3

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

Topic 2: More Shell Skills

Transcription:

Lab 4a Shell Script Lab 2 Using echo command in shell script Objective Upon completion of this lab, the student will be able to use echo command in the shell script. Scenario The student is the administrator of a Linux server who wants to use echo command in the shell script. Procedures Login into Fedora operating system. Use a text editor such as gedit, vi or emacs. Write required Linux commands and logic in the file. Save and close the file (exit from gedit, vi or emacs). Make the script executable. Test the script by running it, and verify the output. Step 1: Creating the Script 1. Login into Fedora operating system. 2. Launch gedit Text Editor by clicking on Applications Accessories gedit Text Editor 3. Type in the following using gedit text editor: echo This is my first echo statement. echo This is my second echo statement. 4. Save the text as myecho.sh. 5. Go to terminal by click on Application System Tools Terminal 6. Make the file executable and run the script by typing the following commands in the terminal. chmod +x myecho.sh./myecho.sh This is my first echo statement. This is my second echo statement. 1

Step 2: Modify the assignment statement. 1. Open the file myname.sh using gedit text editor. 2. Modify the code as follow by removing the double quotes in line 2 and 3: echo This is my first echo statement. echo This is my second echo statement. 3. Save the text and run the script by typing the following command in the terminal../myecho.sh This is my first echo statement. This is my second echo statement. Reflection: 1) Write a script that will display as follow: 2

3

Lab 4b Shell Script Lab 3 Using assignment statement in shell script Objective Upon completion of this lab, the student will be able to use assignment statement in Linux shell script. Scenario The student is the administrator of a Linux server who wants to create a simple shell script using assignment statement. Procedures Login into Fedora operating system. Use a text editor such as gedit, vi or emacs. Write required Linux commands and logic in the file. Save and close the file (exit from gedit, vi or emacs). Make the script executable. Test the script by running it, and verify the output. Step 1: Creating the Script 1. Login into Fedora operating system. 2. Launch gedit Text Editor by clicking on Applications Accessories gedit Text Editor 3. Type in the following using gedit text editor: MyName= Hello World echo $MyName 4. Save the text as myname.sh. 5. Go to terminal by click on Application System Tools Terminal 6. Make the file executable and run the script by typing the following commands in the terminal. chmod +x myname.sh./myname.sh Hello World Explanation: 4

The second line of code assigns the string "Hello World" to the variable MyName. The three line of code echoes out the value of the variable. Step 2: Modify the assignment statement. 1. Open the file myname.sh using gedit text editor. 2. Modify the code as follow by inserting a few space between MyName and = : MyName = Hello World echo $MyName 3. Save the text and run the script by typing the following commands in the terminal../myname.sh./pass.sh: line 2: MyName: command not found You will notice that the script is not able to run. It is because the shell treats MyName as the name of a command and tries to execute it. In order to make the shell treats MyName as a variable, make sure no spaces are around the "=" sign: MyName= Hello World (works) MyName = Hello World (doesn't work) Step 3: Modifying the echo statement 1. Open the file myname.sh using gedit text editor. 2. Modify the code as follow by removing the space entered in step 3 and the two double quotes in line 3: MyName= Hello World echo $MyName 3. Save the text and run the script by typing the following commands in the terminal. chmod +x myname.sh./myname.sh Hello World 5

As we can see the script is able to run properly with or without a double quotes around the variable. Reflection: 1) What will happen if double quotes are removed in line 2 of the script as followed: MyName=Hello World echo $MyName 2) What will happen if $ sign is removed in line 3 of the script as followed: MyName=Hello World echo MyName 6