
Intro to Bash Scripting for Beginners
Learn the basics of Bash scripting in this introductory session. Get familiar with Bash, gain hands-on experience, and prepare for future exercises using Python and Bash scripts. Understand what Bash is, its benefits, how to write scripts, work with variables, use if statements, and more.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Bridging the gaps Intro to Bash 15/05/2023
Objectives Specific objectives of this session: 1. Get familiar with Bash 2. Hands-on experience with Bash 3. Prepare you for the future exercises You will use Python and Bash scripts for the rest of the course. You have different coding experiences, so this is to have a baseline. 2
Outline 1. A quick introduction to Bash The focus of this session is hands-on experience 2. Exercises in Bash 3
What is Bash? Bash is a command language and command line interpreter. It can be used to interpret commands that carry out various actions. A combination of these commands in a series within a text file is called a Shell script. 4
Why is Bash so neat? 1. Easy to create 2. Easy to handle complicated tasks 3. Easy to run on multiple files with scrips 4. Can be automatically run 5
Writing Bash scripts #!/bin/bash echo This is a print statement echo It will be printed out when running the script 6
Running Bash Run the script with added interpreter: bash scriptname.sh Making the script executable: chmod 755 scriptname.sh ./scriptname.sh 7
Variables #!/bin/bash WholesomeActivity=parasail echo Our 2-year old loves to $WholesomeActivity echo She does it all the time! 8
Variables #!/bin/bash WholesomeActivity=dancing echo Our 2-year old loves to $WholesomeActivity echo She does it all the time! 9
If statements An if statement is a programming conditional statement that performs an action when proven true. General if statement: if [ <expression> ] then <statement> fi ------------------------------------------------------ Example: if [ 8 -lt 12 ] then echo Wow, 8 is smaller than 12! fi If true, then all statements between then and fi will run. Indentation is key for easy readability. 10
How this session is built From here on, it is only exercises There are two documents: 1. Exercises 2. Handout You are expected to do the first five exercises. Advanced and Extra are for those who finish quickly. 11
Acknowledgements The creation of this training material was commissioned by ECDC to Statens Serum Institut with the direct involvement of Gitte Nygaard Aasbjerg, Kasper Thystrup Karstensen, and Leandro Andr s Escobar-Herrera The revision and update of this training material was commissioned by ECDC to Statens Serum Institut with the direct involvement of Gitte Nygaard Aasbjerg, Kasper Thystrup Karstensen, Leandro Andr s Escobar-Herrera 12