Git Product home page Git Product logo

bash-tutorial's Introduction

#!/bin/bash for programmers.

About

This project is used for workshop purposes and contains examples of (hopefully) good practices for bash scripting.

Source: https://github.com/steinim/bash-tutorial

Examples

Debugging

Source: scripts/debugging_easy_example.sh and scripts/debugging_tougher_example.sh

The point: Debugging is hard in bash.

Assignment: Find the bugs.

Syntax (readability)

Source: scripts/syntax.sh

The point: You can do similar things in different ways in bash.

Assignment: Try out the different ifs and explain the differences, when to use, and what you prefer.

Functions and configuration

Source: [include/common_functions.sh include/common_config.sh](bash-tutorial/blob/master/include/common_functions.sh include/common_config.sh)

The point: Reduce complexity, enhance testability, and reusability.

Assignment: Go through the functions and try to understand them. Write your own function. How can you run the functions directly from the command line?

Return values and return statuses

Source: include/common_functions.sh (functions: _is_snapshot, _startServers, _find_version_from_pom and _delete)

The point: Understand the differences between a return value and a return status.

Assignment: Revisit the functions and explain what the different functions return (values and/or statuses)

Pitfall return values

Source: scripts/pitfall_return_values.sh

The point: Understand a common pitfall when using return values.

Assignment: Comment in the echo statement in the function and see what happens. Why?

Pitfall return statuses

Source: scripts/pitfall_return_status.sh

The point: Understand a common pitfall when using return statuses.

Assignment: Why do the two statements return different statuses?

Including common functionality

Source: include/includes.sh

The point: Understand reusability by sourcing other files.

Assignment: Write a function in a file and include and use it in a script.

Debugging revisited

Source: [include/common_functions.sh scripts/debugging.sh](bash-tutorial/blob/master/include/common_functions.sh scripts/debugging.sh)

The point: Understand how you can debug your scripts without executing "dangerous" commands. Understand the -x, the -u, and the set -e set +e constructs.

Assignment: Write debugging for a function or script where it is lacking.

Logging

Source: scripts/logging.sh [scripts/rotating_log.sh include/log.sh](bash-tutorial/blob/master/scripts/rotating_log.sh include/log.sh)

The point: Understand how you can write your own logging framework.

Assignment: Write logging configuration to switch between logging to file and stdout.

Unit testing framework

Source: tests/runAll.sh

The point: Example of how you can syntax check and run all your tests.

Assignment: Make a test fail. Make syntax checking fail.

Unit testing using the && and || operators

Source: tests/testMs.sh

The point: An example of how you can unit test bash functions using the && and || operators.

Assignment: Write a unit test. Is this readable?

Unit testing with asserts

Source: bashUnit/asserts.sh tests/testVersionCheck.sh tests/testCheckHealth.sh

The point: An example of how you can unit test bash functions using asserts.

Assignment: How does assertEquals differ from the assertTrue in e. g. jUnit? Write an assertTrue function and a test that uses it. Is this more readable?

Bonus assignment: Write an assertArrayEquals function and a test that uses it.

Organizing files

Source: The project tree.

The point: Understand convention over configuration and why it is important to put different types of files in different places.

Assignment: How would you organize your files when you have specific scripts for different projects residing in different folders.

Packaging your app

Source: scripts/package.sh

The point: An example of how you can package your app.

Assignment: Package your app. What is the result?

Simple deploy and rollback

Source: scripts/deploy.sh scripts/rollback.sh

The point: These scripts are not very testable.

Assignment: Make the scripts testable.

Rerun

Rerun - a simple command runner that turns loose shell scripts into modular automation.

Rerun_image

Thats all folks!

Contact me:

bash-tutorial's People

Contributors

bmaland avatar steinim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.