2013/Pro Bash Development; Way Beyond Shell Scripting

From Open Source Bridge Wiki
Jump to: navigation, search

All Unix/Linux users know a little shell scripting, even if they’re unaware of it. Pipes, for example, are a part of the Bash/sh language. Bash/sh, i.e. shell scripting, is usually treated as just that: shell scripting. But if you’re crazy enough, you can develop full-blown profession, modular, and tested (yes, tested!) programs in Bash. It takes a little finesse, but I’ll show you how, and you just might think twice about using Bash—really using it—in the future.

Speaker: Daniel Nichter

Return to this session's details

Contributed notes

(Add your notes here!)

Pro Bash Development; Way Beyond Shell Scripting testnoir

looking to open a new world of possibilities of scripting.

stigma: scripting in messy. going to look at and address that.

Lets look at: What is a script? bash programming is almost oxymoronic.

what's wrong? useless use of a pipe. how about a command command line command? no

how about a variable? no, still at the command line.

how about a file? yes. it is now. because its in a file, its a script. that's what consensus right now.

so deeper, debugging his slides.

we can do more things: loops, commands on files, looking more and more like a program.

still deeper, can do more verification, validation.

"This is one perceptive audience"

errors not withstanding, what is a script is a fuzzy issue. at what point it becomes a program "One man's script is another man's program"

we could also argue: criteria putting the script into a file. you can open up perl and do the same things, but might not be a script then. sure bash isn't object oriented, but when you put all the line together, it might be arbitrary.

is bash a language? shell, interpreter. can split a lot of hairs.

so if bash isn't a language what is this? (slide about a function ok() { stuff here }

and then perl (strictly speaking, its a slide) sub ok()....

is bash a language? yes and no.

  • shell
  • language
  • glue all together.

deeply time and real-world tested. proven and established

the meat of it: percona-toolkit

like in perl, bash has for bailout

    set -u 

this is just to demonstrate that there are bash libraries to re-implement simple commands to show usage. pid, lsof, ....

he'll have a link on launchpad after the talk.


bash testing - great to have libraries, but need testing too. real unit and integration test with a framework.

do people test their bash code? only two people raised their hands. Then someone asked if running the code to see if it breaks everything counts and he said yes. The rest of the room then raised their hands.

perl: test anything path. nothing like testunit or junit. if you didn't know, you'd think perl module being tested.

but in fact testing bash programs!

takes a lot of bash to simulate perl's testing framework in bash.

bash testing:

  * perl lib.t
  * loads test-bash-func
  * loads lib.sh
  * ...

coolness factor: people say bash is old. yet some people like classics.... like a classic camero.

advanced bash scripting: http://tldb.org/LDP/abs/html

Percona Toolkit https://launchpad.net/percona-toolkit