Huy Minh Ha

Software development, Tech and other stuff

Sun 23 November 2014

An Introduction to Bash

Posted by Ha.Minh in Programming   

BASH

REFERENCES

General Documents, Books, Tutorials

Linting

Unit Testing

Profiling

Debugging

BASICS

Run a bash script

Forking a new shell

    # dot slash
    ./script.sh

    # specifying the shell interpreter
    bash script.sh

Executes the script in the current shell without forking a new shell

    # dot space dot slash
    . ./script.sh

    # source command : similar to dot space dot slash
    source script.sh

Block Comment

    #! /usr/bin/env bash
    : <<COMMENT
    Copyright (C) 2012 Author <author at gmail dot com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation version 3.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    COMMENT

    version="v0.1.1"

Looping in bash

Exit on error with set -e

  • Call set -e in your bash and it will exit if any command returns any error.
  • Call set -evx or bash -evx script.sh to debug script.

Get current bash file folder

    DIR="$( cd -P "$( dirname "$0" )" && pwd )"
Brought to you by pelican_git. view original bash.md


    
 
 

Comments