Shell Scripting

Shell Scripting

Shell scripting is the process of writing lists of commands to be run as a macro from a computer's shell ( or Terminal). These can contain any executable function, as well as a few others, that you would normally run in a Terminal. Once completed these macros can be instructed to run automatically upon different system events or times to help you to automate your life.

Jason Merlo

April 28, 2015

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

61 slides
  1. .sh

  2. #!/bin/bash #check for arguments if [[ $# -lt 2 ]]

    ; then echo "$0: illegal number of params" echo "usage: [dest folder] [backup dirs...]" exit 1 fi …
  3. #!/bin/bash #check for arguments if [[ $# -lt 2 ]]

    ; then echo "$0: illegal number of params" echo "usage: [dest folder] [backup dirs...]" exit 1 fi …
  4. #!/bin/bash #check for arguments if [[ $# -lt 2 ]]

    ; then echo "$0: illegal number of params" echo "usage: [dest folder] [backup dirs...]" exit 1 fi …
  5. #!/bin/bash #check for arguments if [ “$#” -lt 2 ]

    ; then echo "$0: illegal number of params" echo "usage: [dest folder] [backup dirs...]" exit 1 fi …
  6. #!/bin/bash #check for arguments if [[ $# -lt 2 ]]

    ; then echo "$0: illegal number of params" echo "usage: [dest folder] [backup dirs...]" exit 1 fi …
  7. #!/bin/bash #check for arguments if [[ $# -lt 2 ]]

    then echo "$0: illegal number of params" echo "usage: [dest folder] [backup dirs...]" exit 1 fi …
  8. #!/bin/bash #check for arguments if [[ $# -lt 2 ]]

    ; then echo "$0: number of params" echo "usage: [dest folder] [backup dirs...]" exit 1 fi …
  9. #!/bin/bash #check for arguments if [[ $# -lt 2 ]]

    ; then echo "$0: illegal number of params" echo "usage: [dest folder] [backup dirs...]" exit 1 fi …
  10. … create_backup () { #archive file name archive="$host-$day-$1.tgz" #print start

    message echo echo "Backing up $1 to $dest_folder/$archive” echo #compress files using tar tar czvf "$dest_folder/$archive" "$1" } …
  11. … create_backup () { #archive file name archive="$host-$day-$1.tgz" #print start

    message echo echo "Backing up $1 to $dest_folder/$archive” echo #compress files using tar tar czvf "$dest_folder/$archive" "$1" } …
  12. … count=0 for folder in "$@"; do test $count -eq

    0 | | (create_backup $folder) count+=1 done …
  13. … count=0 for folder in "$@"; do test $count -eq

    0 | | (create_backup $folder) count+=1 done …
  14. … count=0 for folder in “$@" do test $count -eq

    0 | | (create_backup $folder) count+=1 done …
  15. … count=0 for folder in "$@"; do test $count -eq

    0 | | (create_backup $folder) count+=1 done …
  16. … count=0 for folder in "$@"; do test $count -eq

    0 | | (create_backup $folder) count+=1 done …
  17. … count=0 for folder in "$@"; do test $count -eq

    0 | | (create_backup $folder) count+=1 done …
  18. time=$(date “+%H”) case $time in [6-10]) echo “morning”;; [11-5]) echo

    “day”;; [6-10]) echo “evening”;; *) echo “night”;; esac

Other Decks in Programming