Project Bash Shell System Programming I Alex Jamieson
Project: Bash Shell System Programming I Alex Jamieson, Ezequiel Jackson, & Chris Haley Team B Amazon Apprentice Program Center for Info. Assurance Education (CIAE) (NSA/DHS CAE-CDE)
Agenda ▰ ▰ Introduce team Discuss scope of project Exercises overview What we learned 2
Alex Jamieson - Exercises ▰ Chapter 1 Exercise 1 ▻ Create a main directory and two subdirectories ▻ /home/ubuntu/bpl/bin ▻ /home/ubuntu/bpl/scripts ▻ Using the mkdir command ▰ Chapter 3 Exercise 2 ▻ Check whether a file exists ▻ Use a while loop and nested if loop ▻ Continues to prompt user until user input is a valid file 3
Alex Jamieson - Exercises ▰ Chapter 4 Exercise 1 ▰ Question: How many arguments are there on this command line? sa $# $(date "+%Y %m %d") John Doe ▻ Answer: 3 ▻ ▻ sa is a command $# expands the number of arguments $(date "+%Y %m %d"), John, and Doe arguments ▰ Chapter 6 Exercise 1 ▻ IFS=. vs ${1//. /} ▻ IFS (Internal Field Separator) - By default is the IFS is a space ▻ Parameter Expansion - ${var//pattern/string} 4
Alex Jamieson - Exercises ▰ Chapter 7 Exercise 3 ▻ Created a function called palindrome ▻ Retrieved user input ▻ Ran function against user input 5
Ezequiel Jackson – Exercises • year=$( date +%Y ) • month=$( date +%m ) • day=$( date +%d ) • hour=$( date +%H ) • minute=$( date +%M ) • second=$( date +%S ) This would give you an incorrect date, and you are writing date 6 times when you only need to write it once. 5. 2: For Single Variable names are reasonable: when used, within the space up to three lines. Index variables when iterating over a list e. g. I, n, k. Equations: var prices = [50, 20, 30]; var discount =. 9; _. map(prices, function (p) {return p * discount; }); // -> [45, 18, 27] 6
Ezequiel Jackson – Exercises 1. 2 & 7. 2 exercises 7
Ezequiel Jackson – Exercises 8
Chris Haley – Exercises ▰ Chapter 2 Exercise 2 ▻ Generate numbers using $RANDOM ▻ Output numbers to a file and a variable ▰ Chapter 3 Exercise 1 ▻ Question: Enter a number between 20 and 30 and ask again if invalid ▻ Until loop with nested if statements 9
Chris Haley – Exercises ▰ Chapter 5 Exercise 3 ▻ Extract 168 using parameter expansion -- var=192. 168. 0. 123 ▻ echo ${var: 4: 3} 10
Chris Haley - Exercises ▰ Chapter 6 Exercise 2 ▻ Add ability to verify a variable is a valid name to max 3() ▰ Chapter 7 Exercise 4 ▻ Write two functions: ltrim & rtrim ▻ Regular expresions ▻ [[ "$ltrim" =~ ^' '*([characters])(. *) ]] ▻ [[ "$rtrim" =~ ^(' '*)(. *)([a-z, A-Z, 0 -9])' '*$ ]] 11
What we learned ▰ Regular expressions ▰ Linux system programming ▰ Bash syntax and commands 12
Key references ▰ Johnson, C. F. A. & Varma, J. (2015). Pro Bash Programming: Scripting the GNU/Linux Shell Second Edition. Apress. (9781484201220) 13
- Slides: 13