210 likes | 240 Views
Project: Bash Shell System Programming I. Connor Matza, Phillip Preyer, Mahansa Poudel Team G Amazon Apprentice Program Center for Info. Assurance Education (CIAE) (NSA/DHS CAE-CDE). Agenda. Mahansa Poudel- Phillip Preyer - Connor Matza – Shell Functions and String Manipulation.
E N D
Project: Bash Shell System Programming I Connor Matza, Phillip Preyer, Mahansa Poudel Team GAmazon Apprentice Program Center for Info. Assurance Education (CIAE) (NSA/DHS CAE-CDE)
Agenda • Mahansa Poudel- • Phillip Preyer - • Connor Matza – Shell Functions and String Manipulation
Mahansa Poudel Chapter 1 • EXERCISE 1 • Write a script that creates a directory called bpl inside $HOME. Populate this directory with two subdirectories, bin and scripts.
Mahansa Poudel Chapter 1 • EXERCISE 2 Q. Write a script to create the "Hello, World!" script, hw, in $HOME/bpl/bin/; make it executable; and then execute it.
Phillip Preyer Chapter 2 1. What is wrong with this command? tr A Z < $HOME/temp > $HOME/temp The addition of the second redirect and the third argument is redundant and will result is the content of the file “temp” being erased completely. (tr is the Translate command)
Phillip Preyer Chapter 2 2. Write a script, using $RANDOM, to write the following output both to a file and to a variable. https://repl.it/@PhilPreyer/Phillip-Preyer
Mahansa Poudel Chapter 3 Exercise 1. • Write a script that asks the user to enter a number between 20 and 30. If the user enters an invalid number or a non-number, ask again. Repeat until a satisfactory number is entered. https://repl.it/@mpoudel/Chapter-3-Exercise-1
Mahansa Poudel Chapter 3 Exercise 2. Write a script that prompts the user to enter the name of a file. Repeat until the user enters a file that exists.
Mahansa Poudel Chapter 4 Exercise 1. • How many arguments are there on this command line? sa $# $(date "+%Y %m %d") John\ Doe • 5
Mahansa Poudel Chapter 4 Exercise 1. • What potential problem exists with the following snippet? • year=$( date +%Y ) month=$( date +%m ) day=$( date +%d ) hour=$( date +%H ) minute=$( date +%M ) second=$( date +%S ) ANS: The commands are not in a single line command. Each output is different when entered separately.
Phillip Preyer Chapter 5 Example of a legitimate use for a single letter variable name: https://repl.it/@PhilPreyer/ch5Q2
Phillip Preyer Chapter 5 Given var=192.168.0.123 write a script that uses parameter expansion to extract the second number, 168 echo ${var:4:3} starting at position 4 and returning 3 characters
Chapter 6 Exercise 1 • Modify the existing isvalidip function to not use a local IFS and instead use Regex • https://repl.it/@jaghadai/Chapter6Exercise1
Chapter 6 Exercise 2 • Modify the Max3 script to include a check for a valid output variable name • https://repl.it/@jaghadai/Chapter6Exercise2
Connor Matza Chapter 7 Exercise 1 • What's wrong with this code? • if ! echo ${PATH} |grep -q /usr/games PATH=$PATH:/usr/games fi (Other than indentation that makes me sad) • Answer – the if statement is missing a then.
Phillip Chapter 7 Exercise 2 Write a function called to_lower() that does the opposite of the to_upper function in Listing 7-4 https://repl.it/@PhilPreyer/Chapter-7-Q-2
Connor Matza Chapter 7 Exercise 3 • Write a script to determine if a string is a palindrome. • Sed s/'\r'$/ main.sh • Subshells are weird. • https://repl.it/@jaghadai/Chapter7Ex3Palindrome
Connor Matza Chapter 7 Exercise 4 • Modify an existing trim() function to enable ltrim() and rtrim() (left and right trim) • https://repl.it/@jaghadai/Chapter7Ex4
Lessons Learned • Stack. Over. Flow. http://www.stackoverflow.com • Being able to write code and test at the same time is a huge benefit for small projects. • Regexes are Powerful
References • http://www.stackoverflow.com • http://www.repl.it • Johnson, C, A (2015) Pro Bash Programming: Scripting the GNU/Linux Shell, Second Edition. Apress.