1 / 20

Project: Bash Shell System Programming I

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.

wandab
Download Presentation

Project: Bash Shell System Programming I

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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)

  2. Agenda • Mahansa Poudel-  • Phillip Preyer - • Connor Matza – Shell Functions and String Manipulation

  3. 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. 

  4. 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.

  5. 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)

  6. 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

  7. 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

  8. 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.

  9. Mahansa Poudel Chapter 4 Exercise 1. • How many arguments are there on this command line?      sa $# $(date "+%Y %m %d") John\ Doe • 5

  10. 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.

  11. Phillip Preyer Chapter 5 Example of a legitimate use for a single letter variable name: https://repl.it/@PhilPreyer/ch5Q2

  12. 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

  13. Chapter 6 Exercise 1 • Modify the existing isvalidip function to not use a local IFS and instead use Regex • https://repl.it/@jaghadai/Chapter6Exercise1

  14. Chapter 6 Exercise 2 • Modify the Max3 script to include a check for a valid output variable name • https://repl.it/@jaghadai/Chapter6Exercise2

  15. 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.

  16. 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

  17. 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

  18. 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

  19. 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

  20. References • http://www.stackoverflow.com • http://www.repl.it  • Johnson, C, A (2015) Pro Bash Programming:  Scripting the GNU/Linux Shell, Second Edition. Apress.

More Related