SlideServe
Menu
Préférences
© SlideServe · v2026

Project: Bash Shell System Programming I

wandab avatar
20 diapositives · 271 Views · Oct 31, 2019

Explore various shell scripting exercises including directory creation, string manipulation, file validation, and functions. Enhance your Bash skills with these practical examples.

Project: Bash Shell System Programming I - slide 1
01 / 20Project: Bash Shell System Programming I
1 / 17

Télécharger la présentation

Project: Bash Shell System Programming I
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  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.