Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Bash Scripting - making your life easier

Bash Scripting - making your life easier

A talk for the biggest java conference in Bulgaria - Java2Days

Preslav Mihaylov

November 16, 2016
Tweet

More Decks by Preslav Mihaylov

Other Decks in Programming

Transcript

  1.  What is a shell  How do we interact

    with the shell  Introduction to Bash scripting  Exploring Bash script syntax  Real world issues  When not to use Bash  Exploring all the different commands  In-depth coverage of bash features Agenda
  2. The shebang... #!/bin/bash  … defines the program which will

    interpret the script   … is stationed on the first line of the script 
  3. Redirecting I/O  One of the most powerful features 

     Allows us to combine programs together
  4. How NOT to use them  echo $STR_pesho  

    Correct way:  echo ${STR}_pesho
  5. Working with text  Parses text as is:  echo

    ’Hello $STR’   Interpolates text:  echo “Hello $STR”   Gets the output of the command:  echo “Hello $(cat name.txt)”
  6. Making decisions  If <condition>; then  ...  elif

    <condition>; then  …  else  …  fi  Syntax:
  7. Making decisions  The condition format depends on the brackets

    used   The brackets can be of many kinds. Depending on them you can do arithmetic expressions, regex, etc...   A short tutorial:  Bash scripting if statements
  8. Repetition structures  for var in list; do … 

    done   while <condition>; do …  done  Syntax:
  9. Repetition structures  The list is a string with whitespace

    (depends on IFS) separated values   The var is a shell variable which acts as an iterator over the list   The condition works the same way it works with Decision structures
  10. Three points of view  The User   The

    Developer   The Sysadmin
  11. The User wants to...  … avoid tedious tasks. 

    … automate his daily tasks.  … customize his shell the way he wants.
  12. The Developer wants to...  … do his work in

    peace.  … build his project appropriately.  … tune up his OS a bit.
  13. The Sysadmin wants to...  … automate his work in

    order to play Counter Strike.  … maintain a stable system.  … avoid dealing with Users.
  14. Resources  TLDP - Intro Bash Scripting  TLDP -

    Advanced Bash Scripting  From Bash to Z Shell 
  15. The GUI makes the simple tasks - even simpler. The

    Shell makes the impossible tasks - possible