Linux Bash Shell Scripting
|
|
- Sandra Griffith
- 5 years ago
- Views:
Transcription
1 University of Chicago Initiative in Biomedical Informatics Computation Institute Linux Bash Shell Scripting Present by: Mohammad Reza Gerami
2 Day 2 Outline Support Review of Day 1 exercise Unix Shell programming: Shell scripts Variables Exercise #1 10 minute break Expression statements Control statements Input parameters (read and variables) Exercise #2 2
3 Where to get the slides 3
4 University of Chicago Initiative in Biomedical Informatics Computation Institute Support
5 Major Offerings Main Cluster (ibicluster) Large Memory Computation Linux (brdfbigl) Large Memory Computation Windows(brdfbigw) Ancillary Clusters (brdfbmem,ibidaily, etc) Database Offerings (mysql, postgres, mssql) Project Shares 5
6 CI-iBi Support ibi Website: BRDF Website: Support Address By Support Phone Number (773)
7 Day 2 Outline Support Review of Day 1 exercise Unix Shell programming: Shell scripts Variables Exercise #1 10 minute break Expression statements Control statements Input parameters (read and variables) Exercise #2 7
8 University of Chicago Initiative in Biomedical Informatics Computation Institute Connect to Linux via Shell $ ssh username@brdfgate.uchicago.edu $ ssh brdfbigl
9 Day 1 Exercise Overview Question: what organisms and functions do the given sequences belong to? Commands used: wget get the protein sequence data from the internet tar to uncompress the data acquired mkdir & cd to organize the data cat to concatenate similar files into one file edit a file used nano to edit the file containing multiple sequences with the same id blastall to perform sequence alignment and comparison to a set of sequences from a database grep to get the top hit for each query sequence cut to get the id of the top hit fastacmd to get the fasta sequence given the id we are interested in 9
10 fasta file >gi gb AAD cytochrome b [Elephas maximus maximus] LCLYTHIGRNIYYGSYLYSETWNTGIMLLLITMATAFMGYVLPWGQMSFWGATVITNLFSAIPYIGTNLV EWIWGGFSVDKATLNRFFAFHFILPFTMVALAGVHLTFLHETGSNNPLGLTSDSDKIPFHPYYTIKDFLG LLILILLLLLLALLSPDMLGDPDNHMPADPLNTPLHIKPEWYFLFAYAILRSVPNKLGGVLALFLSIVIL GLMPFLHTSKHRSMMLRPLSQALFWTLTMDLLTLTWIGSQPVEYPYTIIGQMASILYFSIILAFLPIAGX IENY >sequence_1 MDSKGSSQKGSRLLLLLVVSNLLLCQGVVSTPVCPNGPGNCQVSLRDLFDRAVMVSHYIHDLSS EMFNEFDKRYAQGKGFITMALNSCHTSSLPTPEDKEQAQQTHHEVLMSLILGLLRSWNDPLYHL VTEVRGMKGAPDAILSRAIEIEEENKRLLEGMEMIFGQVIPGAKETEPYPVWSGLPSLQTKDED ARYSAFYNLLHCLRRDSSKIDTYLKLLNCRIIYNNNC Sequences are separated by the ">" character First line sequence ID (unique) description (optional) Next lines Amino acid or nucelotide sequence composition 10
11 BLAST output QUERY_ID HIT_ID IDENTITY LENGTH MIS GAPS Q_ST Q_END H_ST H_END E-VAL P-SCO sequence_1 gi sequence_1 gi sequence_1 gi sequence_1 gi sequence_1 gi sequence_1 gi sequence_1 gi sequence_1 gi sequence_1 gi sequence_2 gi sequence_2 gi QUERY_ID ID for your query sequence HIT_ID ID for the alignment hit IDENTITY percent of amino acids in alignment that exactly match LENGTH length of alignment MIS number of mismatches in the alignment GAPS number of gaps in the alignment Q_ST query start Q_END query end H_ST hit start H_END hit end E-VAL e-value (the lower the better) P-SCO p-score (the higher the better) 11
12 Caveats There are no "one size fits all" solutions Always test scripts Make sure you completely understand new commands and techniques You will not be able to learn everything about bash scripting today Try examples to get familiar Use the web to find help on how to do things All the examples we go through are available in: /biodba/workshopdir/april_2010/day_2/exercises 12
13 The shell of Linux Linux has a variety of different shells: Bourne Again shell (bash) Why write shell scripts? To avoid repetition: If you do a sequence of steps with standard Unix commands over and over, why not do it all with just one command? Or in other words, store all these commands in a file and execute them one by one To automate difficult tasks: Many commands have subtle and difficult options that you don't want to figure out or remember every time 13
14 Simple Clean-up Example Assume that I need to clean up a directory every time before executing BLAST program $ rm rf *.stderr $ rm rf *.stdout $ rm rf *.tmp 14
15 Shell scripts List of command, executed in order The shebang line: #! tells the CPU what shell to use to execute script The shell name is the shell that will execute this script. E.g: #!/bin/bash (which we will use) which command $ which bash /bin/bash If no shell is specified in the script file, the default is chosen to be the executing shell 15
16 The first bash script Write programs using your favorite text editor vi, emacs, nano, pico, etc. So fire up a text editor; for example: $ mkdir ~/scripts $ cd scripts $ nano hello.sh Type the following inside it: #!/bin/bash # This is a commented line, will not be executed # This is my first script "Hello World" echo "Hello World" The first line tells Linux to use the bash interpreter to run this script Make the script executable: $chmod u+x hello.sh $ls l -rwxr--r-- hello.sh 16
17 To execute the program: $ hello.sh The first bash program -bash: hello.sh: command not found $PATH environment variable holds the location where all commands are stored $ echo $PATH /usr/bin:/bin:/usr/sbin The home directory (where the command hello.sh is located) is not in the variable PATH We must specify the path of hello.sh $ /cchome/arodrigu1/scripts/hello.sh 17 $./hello.sh Hello World
18 Back to the clean-up example We can put all those commands into a shell script, called mycleandir.sh $ nano mycleandir.sh #!/bin/bash rm rf *.stderr rm rf *.stdout rm rf *.tmp echo "Deleted files with suffix blastout, stderr, stdout, tmp" Need to make it executable $ chmod u+x mycleandir.sh Run your script and it will be processed in order $./mycleandir.sh 18
19 Variables There are two types of variables: Environmental variables Local variables 19
20 Environmental Variables Environmental variables hold special values. Environmental variables are set by the system on initial login /etc/profile, /etc/profile.d/ and ~/.bash_profile or ~/.profile. If you want to know what the variable holds call it with a "$" sign: $ echo SHELL SHELL $ echo $SHELL /bin/bash $ echo $HOME /cchome/arodrigu1 $ echo $PATH /usr/x11r6/bin:/usr/local/bin:/bin:/usr/bin env command 20
21 Special Environmental Variables: PATH PATH: The search path for commands Usually, we type in the commands in the following way: $./hello.sh By setting PATH=$PATH:~/scripts our working directory is included in the search path for commands, and we simply use the export command: 21 $ export PATH=$PATH:~/scripts $ hello.sh
22 More Environmental Variables LOGNAME: contains the user name HOSTNAME: contains the computer name. MACHTYPE: system hardware BLASTDB: directory path where the blast database are stored PWD: current path you are at 22
23 Local Variables We can use variables as in any programming languages Stored as strings Declaring a variable: $ STR='Hello World!' $ echo $STR Hello World! Assign a value to a variable Call the variable by putting the '$' at the beginning 23
24 Double Quotes When assigning character data containing spaces or special characters, the data must be enclosed in either single or double quotes. Using double quotes (partial quoting) to show a string of characters will allow any variables in the quotes to be resolved $ var="test string" $ newvar="value of var is $var" $ echo $newvar Value of var is test string 24
25 Single Quotes Using single quotes (full quoting) to show a string of characters will not allow variable resolution $ newvar='value of var is $var' $ echo $newvar Value of var is $var 25
26 Command Substitution The backquote "`" is different from the single quote " ". It is used for command substitution: `command` You can assign the output of a command to a variable $ ls hello.sh mycleandir.sh $ LIST=`ls` $ echo $LIST hello.sh mycleandir.sh 26
27 Exercise #1 Create a bash shell script that when executed will print: $ hello_user.sh Hello arodrigu1! Your home is: /cchome/arodrigu1 Today's date is: Fri Mar 19 18:19:42 CDT 2010 Hint: You can get the date by using the date command 27
28 Exercise #1: Solution $ nano hello_user.sh #!/bin/bash echo "Hello $LOGNAME!" echo "Your home is: $HOME" mydate=`date` echo "Today's date is: $mydate" $ chmod u+x hello_user.sh $ export PATH=$PATH:~/scripts $ hello_user.sh 28
29 29 Arithmetic Evaluation expr expression expression operators: arithmetic: +, -, *, /, % comparison: <, <=, ==,!=, >=, > boolean/logical: &, parentheses: (, ) Calculates the value of an expression $ result=`expr 1 + 2` $ echo $result 3 Why do we need the expr command? $ result=1+2 $ echo $result 1+2
30 Control statements Control statements control the flow of execution in a programming language Most common types of control statements: conditionals: if/then/else, case,... loop statements: while, for, until, do,... branch statements: subroutine calls 30
31 Conditional Statements Conditionals lets us decide whether to perform an action or not, this decision is taken by evaluating an expression if [ expression ]; then statements elif [ expression ]; then statements else statements fi ## must have space between brackets ## brackets test an expression the elif (else if) and else sections are optional 31
32 Example grep returns 0 if it finds something returns non-zero otherwise Lets write a script that determines whether unix exists in the file "myfile" 32 $ cp /biodba/workshopdir/april_2010/day2/exercises/*. $ cat if1.sh if grep "UNIX" myfile >/dev/null then echo "It's there" fi $./if1.sh It's there redirect to /dev/null so that "intermediate" results do not get printed This file is available for everyone
33 Using else with if Example: $ cat if2.sh #!/bin/bash if grep "UNIX" myfile2 >/dev/null then echo "UNIX occurs in myfile2" else echo "No!" echo "UNIX does not occur in myfile2" fi $./if2.sh No! UNIX does not occur in myfile2 33
34 Using elif with if $ cat if3.sh #!/bin/bash if grep "UNIX" myfile3 >/dev/null then echo "UNIX occurs in myfile3" elif grep "DOS" myfile3 > /dev/null then echo "DOS appears in myfile3 not UNIX" else echo "nobody is here in myfile3" fi $./if3.sh DOS appears in myfile3 not UNIX 34
35 Expressions Expressions can be: String comparison Numeric comparison File operators Logical operators 35
36 Expressions: String Comparisons String Comparisons: = compare if two strings are equal!= compare if two strings are not equal -n evaluate if string length is greater than zero -z evaluate if string length is equal to zero Examples: [ s1 = s2 ] (true if s1 same as s2, else false) [ s1!= s2 ] (true if s1 not same as s2, else false) [ s1 ] (true if s1 is not empty, else false) [ -n s1 ] (true if s1 has a length greater then 0, else false) [ -z s2 ] (true if s2 has a length of 0, otherwise false) 36
37 Expressions: String Comparisons Compare the user's name given with the environment variable $USER $ cp /biodba/workshopdir/april_2010/day_2/if4.sh./if4.sh $ cat if4.sh #!/bin/bash echo -n "Enter your login name: " # ask user input read name # store input in var if [ "$name" = "$USER" ]; then echo "Hello, $name. How are you today?" else echo "You are not $USER, so who are you?" fi $./if4.sh Enter your login name: arodri You are not arodrigu1, so who are you? 37
38 Expressions: Number Comparisons Number Comparisons: -eq compare if two numbers are equal -ge compare if one number is greater than or equal to a number -le compare if one number is less than or equal to a number -ne compare if two numbers are not equal -gt compare if one number is greater than another number -lt compare if one number is less than another number Examples: [ n1 -eq n2 ] (true if n1 same as n2, else false) [ n1 -ge n2 ] (true if n1greater then or equal to n2, else false) [ n1 -le n2 ] (true if n1 less then or equal to n2, else false) [ n1 -ne n2 ] (true if n1 is not same as n2, else false) [ n1 -gt n2 ] (true if n1 greater then n2, else false) [ n1 -lt n2 ] (true if n1 less then n2, else false) 38
39 Expressions: Number Comparisons Perform a mathematical operation if the number is between a range, otherwise let the user know the number entered is incorrect $ cat if5.sh #!/bin/bash echo -n "Enter a number 1 < x < 10: " # ask user input read num # store input in var if [ "$num" -lt 10 ]; then if [ "$num" -gt 1 ]; then echo "$num*$num=$(($num*$num))" else echo "Wrong insertion!" fi else echo "Wrong insertion!" fi $./if5.sh Enter a number 1 < x < 10: 5 5*5=25 39
40 Expressions: Logical operators Logical operators: && logically AND two logical expressions logically OR two logical expressions Example: the numerical example (if5.sh) can be made into one if statement by using logical operators $ cp /biodba/workshopdir/april_2010/day_2/if7.sh. $ cat if7.sh #!/bin/bash echo -n "Enter a number 1 < x < 10: " read number if [ "$number" -gt 1 ] && [ "$number" -lt 10 ]; then echo "$num*$num=$(($num*$num))" else echo "Wrong insertion!" fi 40 $./if7.sh Enter a number 1 < x < 10: 5 5*5=$25
41 Expressions: File Operators Files operators: -d check if path given is a directory -f check if path given is a file -s check if path given is a symbolic link -e check if file name exists -s check if a file has a length greater than 0 -r check if read permission is set for file or directory -w check if write permission is set for a file or directory -x check if execute permission is set for a file or directory Examples: [ -d fname ] (true if fname is a directory, otherwise false) [ -f fname ] (true if fname is a file, otherwise false) [ -e fname ] (true if fname exists, otherwise false) [ -s fname ] (true if fname length is greater then 0, else false) [ -r fname ] (true if fname has the read permission, else false) [ -w fname ] (true if fname has the write permission, else false) [ -x fname ] (true if fname has the execute permission, else false) 41
42 Expressions: File Operators Check if a certain file exists $ cat if6.sh #!/bin/bash if [ -f /etc/fstab ]; then cp /etc/fstab. echo "Done." else echo "This file does not exist." fi exit 1 $./if6.sh Done. 42
43 for loops for loops allow the repetition of a command for a specific set of values. Syntax: for var in value1 value2... do command_set done command_set is executed with each value of var (value1, value2,...) in sequence 43
44 for loop example 44 Lets calculate the smallest number among a set $ cat for3.sh #!/bin/bash smallest=10000 for i in do echo "evaluation $i" if [ $i -lt $smallest ] then smallest=$i fi done echo $smallest $./for3.sh 3
45 for loop example Lets count the number of files that are executable in current directory $ cat for2.sh #!/bin/bash # initialize variable count=0 for filename in `ls`; do if [ x $filename ] then count=`expr $count + 1` fi done echo "Total of $count files executable" $./for2.sh Total of 5 files executable NOTE: expr $count + 1 adds one to variable 45
46 The while loop While loops repeat statements as long as the next Unix command is successful Syntax: while [ expression ] do command_set done 46
47 while loop example Lets do a summation of every number from 1 to 100 $cat while1.sh #! /bin/bash i=1 # declare var sum=0 # declare var while [ $i -le 100 ] do sum=`expr $sum + $i` i=`expr $i + 1` done echo The sum is $sum. $./while1.sh The sum is
48 while loop example Lets calculate the number of fasta files in a sequence file #!/bin/bash # while2.sh counts the number of fasta sequences found in a fasta file count=0 # initialize a variable that holds # the count of sequences # in each iteration we are going to read the next line in flie while read line do if echo $line grep ">" > /dev/null # determine if the current line # is a sequence header ">" then count=`expr $count + 1` # perform an addition to the count fi done < "sequences.fasta" # define the filename you wish to use # tell me the total count of fasta sequences echo "Your fasta file contains $count sequences" 48
49 Shell Parameters Positional parameters are assigned from the shell's argument when it is invoked ( i.e. ls -l dir1 dir2) Positional parameter "N" may be referenced as "${N}", or as "$N" when "N" consists of a single digit. Special parameters $# is the number of parameters passed $0 returns the name of the shell script running as well as its location in the filesystem $* gives a single word containing all the parameters passed to the script $@ gives an array of words containing all the parameters passed to the script $ cat sparameters.sh #!/bin/bash echo "$#; $0; $1; $2; $*; $@" $ sparameters.sh alba chiara 2;./sparameters.sh; alba; chiara; alba chiara; alba chiara 49
50 Using parameters in while loop example Lets calculate the number of fasta files in a sequence file #!/bin/bash # while3.sh counts the number of fasta sequences found in a fasta file filename=$1 count= # assign the input parameter filename to a variable # initialize a variable that holds the count of sequences # in each iteration we are going to read the next line in flie while read line do if echo $line grep ">" > /dev/null # determine if the current line # is a sequence header ">" then count=`expr $count + 1` # perform an addition to the count fi done < $filename # define the filename you wish to use # tell me the total count of fasta sequences echo "Your fasta file contains $count sequences" 50
51 University of Chicago Initiative in Biomedical Informatics Computation Institute Exercise 2
52 Overview of Exercise Problem: Given a set protein sequences, find out what organism each sequence is from and what each sequence does? Tarball file location: Tarball contains sequence files with multiple sequence with the same ids 52
53 Exercise #2 Create a bash shell script for yesterday's exercise and try to use as many control statements: Get the tar files via wget ( untar the file (fasta_files.tar.gz) concatenate the files (sequences may have the same id) modify the sequence ids use exercise2-skeleton.sh as a startup, variables have been setup Home exercise submit file to blast (blastall command) grep the top hit for each sequence get the hit id use the fastacmd command to get the fasta sequence Solutions located at: /biodba/workshopdir/april_2010/day_2/exercises/exercise2-solution.sh 53
54 fasta file >gi gb AAD cytochrome b [Elephas maximus maximus] LCLYTHIGRNIYYGSYLYSETWNTGIMLLLITMATAFMGYVLPWGQMSFWGATVITNLFSAIPYIGTNLV EWIWGGFSVDKATLNRFFAFHFILPFTMVALAGVHLTFLHETGSNNPLGLTSDSDKIPFHPYYTIKDFLG LLILILLLLLLALLSPDMLGDPDNHMPADPLNTPLHIKPEWYFLFAYAILRSVPNKLGGVLALFLSIVIL GLMPFLHTSKHRSMMLRPLSQALFWTLTMDLLTLTWIGSQPVEYPYTIIGQMASILYFSIILAFLPIAGX IENY >sequence_1 MDSKGSSQKGSRLLLLLVVSNLLLCQGVVSTPVCPNGPGNCQVSLRDLFDRAVMVSHYIHDLSS EMFNEFDKRYAQGKGFITMALNSCHTSSLPTPEDKEQAQQTHHEVLMSLILGLLRSWNDPLYHL VTEVRGMKGAPDAILSRAIEIEEENKRLLEGMEMIFGQVIPGAKETEPYPVWSGLPSLQTKDED ARYSAFYNLLHCLRRDSSKIDTYLKLLNCRIIYNNNC Sequences are separated by the ">" character First line sequence ID (unique) description (optional) Next lines Amino acid or nucelotide sequence composition 54
55 BLAST output QUERY_ID HIT_ID IDENTITY LENGTH MIS GAPS Q_ST Q_END H_ST H_END E-VAL P-SCO sequence_1 gi sequence_1 gi sequence_1 gi sequence_1 gi sequence_1 gi sequence_1 gi sequence_1 gi sequence_1 gi sequence_1 gi sequence_2 gi sequence_2 gi QUERY_ID ID for your query sequence HIT_ID ID for the alignment hit IDENTITY percent of amino acids in alignment that exactly match LENGTH length of alignment MIS number of mismatches in the alignment GAPS number of gaps in the alignment Q_ST query start Q_END query end H_ST hit start H_END hit end E-VAL e-value (the lower the better) P-SCO p-score (the higher the better) 55
56 Take-home Message What we have covered today covers only a little of what is needed You can use what you used today to expand on your knowledge Use different websites to get help Go through the examples on your own time We can use bash shell scripting to submit jobs to the cluster environment 56
57 University of Chicago Initiative in Biomedical Informatics Computation Institute Thank you! Please evaluate our performance for this workshop: Evaluation [ ] Surveys created with REDCap. Survey Hosted at ibi
Bash scripting basics
Bash scripting basics prepared by Anatoliy Antonov for ESSReS community September 2012 1 Outline Definitions Foundations Flow control References and exercises 2 Definitions 3 Definitions Script - [small]
More informationUseful 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 informationA 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 informationMore Linux Shell Scripts
nit 5 ore Linux hell cripts opics for this nit ore shell commands Control statements Constraints xpressions elect command Case command unning hell cripts shell script as a standalone is an executable program
More informationLinux 系统介绍 (III) 袁华
Linux 系统介绍 (III) 袁华 yuanh25@mail.sysu.edu.cn Command Substitution The backquote ` is different from the single quote. It is used for command substitution: `command` $ LIST=`ls` $ echo $LIST We can perform
More informationConditional 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 informationIntroduction: What is Unix?
Introduction Introduction: What is Unix? An operating system Developed at AT&T Bell Labs in the 1960 s Command Line Interpreter GUIs (Window systems) are now available Introduction: Unix vs. Linux Unix
More informationexample: 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 informationEssentials for Scientific Computing: Bash Shell Scripting Day 3
Essentials for Scientific Computing: Bash Shell Scripting Day 3 Ershaad Ahamed TUE-CMS, JNCASR May 2012 1 Introduction In the previous sessions, you have been using basic commands in the shell. The bash
More informationShells & 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 informationShell Scripting. Todd Kelley CST8207 Todd Kelley 1
Shell Scripting Todd Kelley kelleyt@algonquincollege.com CST8207 Todd Kelley 1 If we have a set of commands that we want to run on a regular basis, we could write a script A script acts as a Linux command,
More informationCSCI 211 UNIX Lab. Shell Programming. Dr. Jiang Li. Jiang Li, Ph.D. Department of Computer Science
CSCI 211 UNIX Lab Shell Programming Dr. Jiang Li Why Shell Scripting Saves a lot of typing A shell script can run many commands at once A shell script can repeatedly run commands Help avoid mistakes Once
More informationBasic 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 informationScripting. More Shell Scripts. Adapted from Practical Unix and Programming Hunter College
Scripting More Shell Scripts Adapted from Practical Unix and Programming Hunter College Copyright 2006 2009 Stewart Weiss Back to shell scripts Now that you've learned a few commands and can edit files,
More informationCSCI 2132: Software Development. Norbert Zeh. Faculty of Computer Science Dalhousie University. Shell Scripting. Winter 2019
CSCI 2132: Software Development Shell Scripting Norbert Zeh Faculty of Computer Science Dalhousie University Winter 2019 Reading Glass and Ables, Chapter 8: bash Your Shell vs Your File Manager File manager
More informationIntroduction 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 informationShell 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 informationVi & 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 informationUNIX 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 informationBourne 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 informationUNIX 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 informationTitle:[ Variables Comparison Operators If Else Statements ]
[Color Codes] Environmental Variables: PATH What is path? PATH=$PATH:/MyFolder/YourStuff?Scripts ENV HOME PWD SHELL PS1 EDITOR Showing default text editor #!/bin/bash a=375 hello=$a #No space permitted
More information9.2 Linux Essentials Exam Objectives
9.2 Linux Essentials Exam Objectives This chapter will cover the topics for the following Linux Essentials exam objectives: Topic 3: The Power of the Command Line (weight: 10) 3.3: Turning Commands into
More informationCommand 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 informationWhen talking about how to launch commands and other things that is to be typed into the terminal, the following syntax is used:
Linux Tutorial How to read the examples When talking about how to launch commands and other things that is to be typed into the terminal, the following syntax is used: $ application file.txt
More informationAssignment 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 informationLING 408/508: Computational Techniques for Linguists. Lecture 5
LING 408/508: Computational Techniques for Linguists Lecture 5 Last Time Installing Ubuntu 18.04 LTS on top of VirtualBox Your Homework 2: did everyone succeed? Ubuntu VirtualBox Host OS: MacOS or Windows
More informationA Big Step. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers
A Big Step Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers Copyright 2006 2009 Stewart Weiss What a shell really does Here is the scoop on shells. A shell is a program
More informationLinux Systems Administration Shell Scripting Basics. Mike Jager Network Startup Resource Center
Linux Systems Administration Shell Scripting Basics Mike Jager Network Startup Resource Center mike.jager@synack.co.nz These materials are licensed under the Creative Commons Attribution-NonCommercial
More informationScripting. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers
Scripting Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers Adapted from Practical Unix and Programming Hunter College Copyright 2006 2009 Stewart Weiss What a shell
More informationCENG 334 Computer Networks. Laboratory I Linux Tutorial
CENG 334 Computer Networks Laboratory I Linux Tutorial Contents 1. Logging In and Starting Session 2. Using Commands 1. Basic Commands 2. Working With Files and Directories 3. Permission Bits 3. Introduction
More informationShell 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 informationEssential Skills for Bioinformatics: Unix/Linux
Essential Skills for Bioinformatics: Unix/Linux SHELL SCRIPTING Overview Bash, the shell we have used interactively in this course, is a full-fledged scripting language. Unlike Python, Bash is not a general-purpose
More informationLecture 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 informationContents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...
Contents Note: pay attention to where you are........................................... 1 Note: Plaintext version................................................... 1 Hello World of the Bash shell 2 Accessing
More informationShell 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 informationEECS 470 Lab 5. Linux Shell Scripting. Friday, 1 st February, 2018
EECS 470 Lab 5 Linux Shell Scripting Department of Electrical Engineering and Computer Science College of Engineering University of Michigan Friday, 1 st February, 2018 (University of Michigan) Lab 5:
More informationLinux Shell Scripting. Linux System Administration COMP2018 Summer 2017
Linux Shell Scripting Linux System Administration COMP2018 Summer 2017 What is Scripting? Commands can be given to a computer by entering them into a command interpreter program, commonly called a shell
More informationProcesses and Shells
Shell ls pico httpd CPU Kernel Disk NIC Processes Processes are tasks run by you or the OS. Processes can be: shells commands programs daemons scripts Shells Processes operate in the context of a shell.
More informationCS 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 informationTable 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 informationMills HPC Tutorial Series. Linux Basics II
Mills HPC Tutorial Series Linux Basics II Objectives Bash Shell Script Basics Script Project This project is based on using the Gnuplot program which reads a command file, a data file and writes an image
More informationUnix Shell scripting. Dr Alun Moon 7th October Introduction. Notation. Spaces
Unix Shell scripting Dr Alun Moon 7th October 2017 Introduction Shell scripts in Unix are a very powerfull tool, they form much of the standard system as installed. What are these good for? So many file
More informationLec 1 add-on: Linux Intro
Lec 1 add-on: Linux Intro Readings: - Unix Power Tools, Powers et al., O Reilly - Linux in a Nutshell, Siever et al., O Reilly Summary: - Linux File System - Users and Groups - Shell - Text Editors - Misc
More informationBash scripting Tutorial. Hello World Bash Shell Script. Super User Programming & Scripting 22 March 2013
Bash scripting Tutorial Super User Programming & Scripting 22 March 2013 Hello World Bash Shell Script First you need to find out where is your bash interpreter located. Enter the following into your command
More informationShell scripting and system variables. HORT Lecture 5 Instructor: Kranthi Varala
Shell scripting and system variables HORT 59000 Lecture 5 Instructor: Kranthi Varala Text editors Programs built to assist creation and manipulation of text files, typically scripts. nano : easy-to-learn,
More informationCOMS 6100 Class Notes 3
COMS 6100 Class Notes 3 Daniel Solus September 1, 2016 1 General Remarks The class was split into two main sections. We finished our introduction to Linux commands by reviewing Linux commands I and II
More informationUnix 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 informationMore Raspian. An editor Configuration files Shell scripts Shell variables System admin
More Raspian An editor Configuration files Shell scripts Shell variables System admin Nano, a simple editor Nano does not require the mouse. You must use your keyboard to move around the file and make
More informationBASH Programming Introduction
BASH Programming Introduction 1. Very simple Scripts Traditional hello world script: echo Hello World A very simple backup script: tar -czf /var/my-backup.tgz /home/me/ 2. Redirection stdout 2 file: ls
More informationCOMP 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 informationOPERATING 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 informationLinux 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 informationEECS2301. 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 informationShell 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 informationCOMP 2718: Shell Scripts: Part 1. By: Dr. Andrew Vardy
COMP 2718: Shell Scripts: Part 1 By: Dr. Andrew Vardy Outline Shell Scripts: Part 1 Hello World Shebang! Example Project Introducing Variables Variable Names Variable Facts Arguments Exit Status Branching:
More informationShells 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 informationThe 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 informationWindshield. Language Reference Manual. Columbia University COMS W4115 Programming Languages and Translators Spring Prof. Stephen A.
Windshield Language Reference Manual Columbia University COMS W4115 Programming Languages and Translators Spring 2007 Prof. Stephen A. Edwards Team members Wei-Yun Ma wm2174 wm2174@columbia.edu Tony Wang
More informationLinux Training. for New Users of Cluster. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala
Linux Training for New Users of Cluster Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala pakala@uga.edu 1 Overview GACRC Linux Operating System Shell, Filesystem, and Common
More informationComputer 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 informationLinux shell programming for Raspberry Pi Users - 2
Linux shell programming for Raspberry Pi Users - 2 Sarwan Singh Assistant Director(S) NIELIT Chandigarh 1 SarwanSingh.com Education is the kindling of a flame, not the filling of a vessel. - Socrates SHELL
More informationUnderstanding bash. Prof. Chris GauthierDickey COMP 2400, Fall 2008
Understanding bash Prof. Chris GauthierDickey COMP 2400, Fall 2008 How does bash start? It begins by reading your configuration files: If it s an interactive login-shell, first /etc/profile is executed,
More informationComputer Systems and Architecture
Computer Systems and Architecture Stephen Pauwels UNIX Scripting Academic Year 2018-2019 Outline Basics Conditionals Loops Advanced Exercises Shell Scripts Grouping commands into a single file Reusability
More informationBashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009
Bashed One Too Many Times Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009 What is a Shell? The shell interprets commands and executes them It provides you with an environment
More informationCSC 2500: Unix Lab Fall 2016
CSC 2500: Unix Lab Fall 2016 Control Statements in Shell Scripts: Decision Mohammad Ashiqur Rahman Department of Computer Science College of Engineering Tennessee Tech University Agenda User Input Special
More informationIntroduction to Shell Scripting
Introduction to Shell Scripting Lecture 1. Shell scripts are small programs. They let you automate multi-step processes, and give you the capability to use decision-making logic and repetitive loops. 2.
More informationAdvanced Unix Programming Module 03 Raju Alluri spurthi.com
Advanced Unix Programming Module 03 Raju Alluri askraju @ spurthi.com Advanced Unix Programming: Module 3 Shells & Shell Programming Environment Variables Writing Simple Shell Programs (shell scripts)
More informationLecture 4. Log into Linux Reminder: Homework 1 due today, 4:30pm Homework 2 out, due next Tuesday Project 1 out, due next Thursday Questions?
Lecture 4 Log into Linux Reminder: Homework 1 due today, 4:30pm Homework 2 out, due next Tuesday Project 1 out, due next Thursday Questions? Tuesday, September 7 CS 375 UNIX System Programming - Lecture
More informationShell 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 information12.1 UNDERSTANDING UNIX SHELL PROGRAMMING LANGUAGE: AN INTRODUCTION Writing a Simple Script Executing a Script
12 Shell Programming This chapter concentrates on shell programming. It explains the capabilities of the shell as an interpretive high-level language. It describes shell programming constructs and particulars.
More informationbash Execution Control COMP2101 Winter 2019
bash Execution Control COMP2101 Winter 2019 Bash Execution Control Scripts commonly can evaluate situations and make simple decisions about actions to take Simple evaluations and actions can be accomplished
More informationBourne 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 informationShells 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 informationbash Tests and Looping Administrative Shell Scripting COMP2101 Fall 2017
bash Tests and Looping Administrative Shell Scripting COMP2101 Fall 2017 Command Lists A command is a sequence of commands separated by the operators ; & && and ; is used to simply execute commands in
More informationPreview. 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 informationBash shell programming Part II Control statements
Bash shell programming Part II Control statements Deniz Savas and Michael Griffiths 2005-2011 Corporate Information and Computing Services The University of Sheffield Email M.Griffiths@sheffield.ac.uk
More informationShell Scripting. With Applications to HPC. Edmund Sumbar Copyright 2007 University of Alberta. All rights reserved
AICT High Performance Computing Workshop With Applications to HPC Edmund Sumbar research.support@ualberta.ca Copyright 2007 University of Alberta. All rights reserved High performance computing environment
More informationScazLab. Linux Scripting. Core Skills That Every Roboticist Must Have. Alex Litoiu Thursday, November 14, 13
Linux Scripting Core Skills That Every Roboticist Must Have Alex Litoiu alex.litoiu@yale.edu 1 Scazlab Topics Covered Linux Intro - Basic Concepts Advanced Bash Scripting - Job scheduling - File system
More informationUnix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University
Unix/Linux Basics 1 Some basics to remember Everything is case sensitive Eg., you can have two different files of the same name but different case in the same folder Console-driven (same as terminal )
More information30 Bash Script Examples
30 Bash Script Examples 6 months ago by Fahmida Yesmin Bash scripts can be used for various purposes, such as executing a shell command, running multiple commands together, customizing administrative tasks,
More informationbash Tests and Looping Administrative Shell Scripting COMP2101 Fall 2017
bash Tests and Looping Administrative Shell Scripting COMP2101 Fall 2017 Command Lists A command is a sequence of commands separated by the operators ; & && and ; is used to simply execute commands in
More informationUNIX 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 informationShell script. Shell Scripts. A shell script contains a sequence of commands in a text file. Shell is an command language interpreter.
Shell Scripts A shell script contains a sequence of commands in a text file. Shell is an command language interpreter. Shell executes commands read from a file. Shell is a powerful programming available
More informationChapter 9. Shell and Kernel
Chapter 9 Linux Shell 1 Shell and Kernel Shell and desktop enviroment provide user interface 2 1 Shell Shell is a Unix term for the interactive user interface with an operating system A shell usually implies
More informationUnix basics exercise MBV-INFX410
Unix basics exercise MBV-INFX410 In order to start this exercise, you need to be logged in on a UNIX computer with a terminal window open on your computer. It is best if you are logged in on freebee.abel.uio.no.
More informationIntroduction to Shell Scripting
Introduction to Shell Scripting Evan Bollig and Geoffrey Womeldorff Presenter Yusong Liu Before we begin... Everyone please visit this page for example scripts and grab a crib sheet from the front http://www.scs.fsu.edu/~bollig/techseries
More informationExploring UNIX: Session 3
Exploring UNIX: Session 3 UNIX file system permissions UNIX is a multi user operating system. This means several users can be logged in simultaneously. For obvious reasons UNIX makes sure users cannot
More informationCisco 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 informationUsing bash. Administrative Shell Scripting COMP2101 Fall 2017
Using bash Administrative Shell Scripting COMP2101 Fall 2017 Bash Background Bash was written to replace the Bourne shell The Bourne shell (sh) was not a good candidate for rewrite, so bash was a completely
More informationShell. 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 informationLecture 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 informationOperating Systems. Lab Manual. Compiled by: Mr. Mohammed Al-Qadhi Computer Science Department
J A Z A N U N I V E R S I T Y C O M P U T E R S C I E N C E D E P A R T M E N T Operating Systems Lab Manual Compiled by: Mr. Mohammed Al-Qadhi Computer Science Department Table of Contents First Lab Session...
More informationIntroduction to UNIX command-line II
Introduction to UNIX command-line II Boyce Thompson Institute 2017 Prashant Hosmani Class Content Terminal file system navigation Wildcards, shortcuts and special characters File permissions Compression
More informationUnix 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Програмиранев 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 informationLab 4: Shell scripting
Lab 4: Shell scripting Comp Sci 1585 Data Structures Lab: Tools Computer Scientists Outline 1 2 3 4 5 6 What is shell scripting good? are the duct tape and bailing wire of computer programming. You can
More informationCS Unix Tools & Scripting
Cornell University, Spring 2014 1 February 21, 2014 1 Slides evolved from previous versions by Hussam Abu-Libdeh and David Slater Announcement HW 4 is out. Due Friday, February 28, 2014 at 11:59PM. Wrapping
More informationShell 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 informationUNIX Shell Programming
$!... 5:13 $$ and $!... 5:13.profile File... 7:4 /etc/bashrc... 10:13 /etc/profile... 10:12 /etc/profile File... 7:5 ~/.bash_login... 10:15 ~/.bash_logout... 10:18 ~/.bash_profile... 10:14 ~/.bashrc...
More information