Bash       4
Linux Open Administration Days

        Pieter Colpaert_
#Understanding Bash
 >A little history
 >Reinventing UNIX
#Speaking Bash
#Bash 4
#_
Understanding Bash_
A little history (1970)
And some UNIX today (2010)




                   CC BY-SA – Larry Miller
But also
    #Routers
    #Mainframes
    #Servers
    #Smartphones
    #PDA's
    #Toasters
    #..._
Let's reinvent UNIX
/rules/1# Writing software is one thing.
Making it communicate is another_
Let's reinvent UNIX
          #Communication
            >Systemcalls to
             hardware through
             kernel...
Why Bash?
#Not much knowledge required
#Combines C-shell, Bourne Shell, …
#Free Software
#_
What the hell is wrong with a GUI?
#Nothing
 >For once in a life-time configurations
 >Living today is pretty awesome
#Eve...
Speaking Bash_
Built-in commands

    &, (( )), ., :, [, [[, alias, bg, bind, break, builtin,
  caller, case, cd, command, compgen, compl...
External commands
#Compiled programs
#Bash-scripts
#Alias-commands
#Perl-scripts
#Functions
#_
man-pages
#If you don't know how a command works
  >man command
  >info command
Hello World!
  On stdout:
#echo hello world!
  On stderr:
#echo hello world! >&2
  To a file:
#echo hello world! > HELLOWO...
Input
###################In script
#read a b c
#set -
 Set your $IFS!
###################From CLI
#Script.sh < file
#Here ...
Scripting Basics
#Magic - #!/bin/bash
#Add -x to debug
#Comments - #
#; = EOL
# escapes EOL
#chmod +x
#echo $PATH
Expansion
#VARIABLE=value
 >All-caps not needed, just recommended
#echo ${VARIABLE}
 >{} not always needed, but stops prob...
Expansion

#Command Substitution
 >$(command)
 >`command`
#Tilde
 >~ = your home directory
 >~user = user's home directory...
Expansion
#Prevention
  > escapes a single special character
  >“” escapes all but $, ` and 
  >'' escapes all special cha...
Loops
#for VAR in items in list; do commands; done
#exit status - $?
#test - [ condition ]
#while [ test ]; do commands; d...
Conditional Statements

#Operators
 >&&
 >||
#if [ test ]; then commands
#elif [ test ]; then commands
#else commands
#fi
Conditional Statements

#case VAR in
 >option)
 >commands
 >;;
 >*)
 >commands
 >;;
 >esac
I/O Redirection

#Combining 1 and 2
 >&>
 >&>>
 >2>&1
 >>&2
#Channel 0 – STDIN
 ><
 >-
User Input
#Arguments
 >$1, $2, ${10}, etc.
 >$* or $@
 >$#
Bash 4_
Bash4
#Associative arrays!
#Expansions ~ perl
#Coproc
#..._
Associative Arrays
#Declare -A array
#array[element]=hello
#echo ${array[element]}
New expansions
  Substring
#${#:0:1}
  Case modification
#${var^^}
#${var^}
#${var,}
#${var,,}
Chopping strings
  Get the extension of the current script
#${0##*.}
#${0#*.} (not correct)
  Get the filename without ext...
Examples
Questions




            #CC BY-SA
Upcoming SlideShare
Loading in...5
×

Bash 4

1,898

Published on

My presentation on Bash on loadays

Published in: Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,898
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
50
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Bash 4

  1. 1. Bash 4 Linux Open Administration Days Pieter Colpaert_
  2. 2. #Understanding Bash >A little history >Reinventing UNIX #Speaking Bash #Bash 4 #_
  3. 3. Understanding Bash_
  4. 4. A little history (1970)
  5. 5. And some UNIX today (2010) CC BY-SA – Larry Miller
  6. 6. But also #Routers #Mainframes #Servers #Smartphones #PDA's #Toasters #..._
  7. 7. Let's reinvent UNIX /rules/1# Writing software is one thing. Making it communicate is another_
  8. 8. Let's reinvent UNIX #Communication >Systemcalls to hardware through kernel >Systemcalls to user through a scriptinglanguage_
  9. 9. Why Bash? #Not much knowledge required #Combines C-shell, Bourne Shell, … #Free Software #_
  10. 10. What the hell is wrong with a GUI? #Nothing >For once in a life-time configurations >Living today is pretty awesome #Everything >When you have to configure 20 PC's the same way >When you don't want to install a demo-version of some proprietary tool >When you want to do things fast_
  11. 11. Speaking Bash_
  12. 12. Built-in commands &, (( )), ., :, [, [[, alias, bg, bind, break, builtin, caller, case, cd, command, compgen, complete, compopt, continue, coproc, declare, dirs, disown, echo, enable, eval, exec, exit, export, false, fc, fg, for, for, function, getopts, hash, history, if, jobs, kill, let, local, logout, mapfile, bind, printf, pushd, pwd, read, readarray, readonly, return, set, select, shift, shopt, source, suspend, test, time, times, true, typeset, ulimit, umask, unalias, unset, until, variables, wait, while, { cmd; }
  13. 13. External commands #Compiled programs #Bash-scripts #Alias-commands #Perl-scripts #Functions #_
  14. 14. man-pages #If you don't know how a command works >man command >info command
  15. 15. Hello World! On stdout: #echo hello world! On stderr: #echo hello world! >&2 To a file: #echo hello world! > HELLOWORLD To the end of a file: #echo hello world! >> HELLOWORLD
  16. 16. Input ###################In script #read a b c #set - Set your $IFS! ###################From CLI #Script.sh < file #Here document: #script.sh <<EOF
  17. 17. Scripting Basics #Magic - #!/bin/bash #Add -x to debug #Comments - # #; = EOL # escapes EOL #chmod +x #echo $PATH
  18. 18. Expansion #VARIABLE=value >All-caps not needed, just recommended #echo ${VARIABLE} >{} not always needed, but stops problems >$ is necessary #declare -i VARIABLE=value >Specifies variable is an integer
  19. 19. Expansion #Command Substitution >$(command) >`command` #Tilde >~ = your home directory >~user = user's home directory #Wildcard globs >man 7 glob
  20. 20. Expansion #Prevention > escapes a single special character >“” escapes all but $, ` and >'' escapes all special characters
  21. 21. Loops #for VAR in items in list; do commands; done #exit status - $? #test - [ condition ] #while [ test ]; do commands; done #until [ test ]; do commands; done
  22. 22. Conditional Statements #Operators >&& >|| #if [ test ]; then commands #elif [ test ]; then commands #else commands #fi
  23. 23. Conditional Statements #case VAR in >option) >commands >;; >*) >commands >;; >esac
  24. 24. I/O Redirection #Combining 1 and 2 >&> >&>> >2>&1 >>&2 #Channel 0 – STDIN >< >-
  25. 25. User Input #Arguments >$1, $2, ${10}, etc. >$* or $@ >$#
  26. 26. Bash 4_
  27. 27. Bash4 #Associative arrays! #Expansions ~ perl #Coproc #..._
  28. 28. Associative Arrays #Declare -A array #array[element]=hello #echo ${array[element]}
  29. 29. New expansions Substring #${#:0:1} Case modification #${var^^} #${var^} #${var,} #${var,,}
  30. 30. Chopping strings Get the extension of the current script #${0##*.} #${0#*.} (not correct) Get the filename without extension #${0%.*} #${0%%.*} (not correct)
  31. 31. Examples
  32. 32. Questions #CC BY-SA
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×