shelllings

a practical way to learn shell
Log | Files | Refs | README | LICENSE

19_functions.sh (1172B)


      1 #!/bin/sh
      2 
      3 # There are many times where you would need to repeat large sections of
      4 # code. Or need to simplify the code for readability and organization.
      5 # Functions would be use in this case, this is a simple example of how
      6 # to use a function.
      7 #
      8 # $ greet() {
      9 # $ 	name="$1"
     10 # $ 	echo "Hello, $name."
     11 # $ }
     12 # $
     13 # $ greet Alice		# Hello, Alice.
     14 # $ greet Bob		# Hello, Bob.
     15 #
     16 # Pay attention to the syntax to use this function.
     17 #
     18 # Fix this program
     19 
     20 display_entropy() {
     21 	echo "Entropy available: $(cat /proc/sys/kernel/random/entropy_avail)"
     22 	echo "Entropy pool size: $(cat /proc/sys/kernel/random/poolsize)"
     23 	echo "Wakeup threshold: $(cat /proc/sys/kernel/random/write_wakeup_threshold)" 
     24 	echo "Minimum reseeding in seconds: $(cat /proc/sys/kernel/random/urandom_min_reseed_secs)"
     25 }
     26 
     27 help() {
     28 	echo "Usage: sh 19_functions.sh [OPTION]"
     29 	echo "-en			displays the entropy information of your system"
     30 	echo "-h, --help			displays this help message"
     31 }
     32 
     33 # Write a program where if something runs the program with the option
     34 # '-de' at the end (sh 19_functions.sh -de) it would call the
     35 # display_entropy function. Anything else written, would have the help
     36 # function ran.
     37