Accès direct au contenu Accès direct à la navigation

Bash, the "Bourne-Again-SHell", is a Unix shell written for the GNU Project as a free software replacement for the original Bourne shell (sh). The present library is a tool for Bash scripts facilities. Bash is the language mostly used by Linux/Unix devices terminal or console.

This package is our "bash" library.

Usage of the library

Installation

You can install the package in many ways explained below ; the best practice is to use the internal interface as described below.

Classic install

Once you have downloaded or cloned the package sources, just copy the src/piwi-bash-library.sh file to your project directory and begin to use it ...

For a global usage on your machine, you can copy the library in your bin/ directory.

As for any script file, it must have execution rights for all users.

A direct and complete installation, including downloading sources, could be :

  1. ~$ wget --no-check-certificate https://github.com/atelierspierrot/piwi-bash-library/archive/master.tar.gz
  2. ~$ tar -xvf master.tar.gz
  3. ~$ cp piwi-bash-library-master/src/piwi-bash-library.sh path/to/your/project/bin/
  4. ~$ chmod +x path/to/your/project/bin/piwi-bash-library.sh
Composer install

If you are a Composer user, you can add to your package requirements :

  1.     "atelierspierrot/piwi-bash-library": "1.*"

The library will automatically be added in your package’s bin directory.

Internal interface

The library embeds an internal interface to manage (instal/update/uninstall) the library itself locally or globally. To use it, run :

  1. ~$ path/to/piwi-bash-library.sh help

It is sometimes useful to include the library file to your project and manage it manually under version control. The interface will handle the installation and update of the library files for you.

Usage

To use the library in a bash script, just source it at the top of your code or before any call of its methods or variables :

  1. #!/bin/bash
  2. source path/to/piwi-bash-library.sh

For a complete loading writing an error if the library is not found, use the following :

  1. LIBFILE="path/to/piwi-bash-library.sh"
  2. if [ -f "$LIBFILE" ]; then source "$LIBFILE"; else
  3.     PADDER=$(printf '%0.1s' "#"{1..1000})
  4.     printf "\n### %*.*s\n    %s\n    %s\n%*.*s\n\n" 0 $(($(tput cols)-4)) "ERROR! $PADDER" \
  5.         "Unable to find required library file '$LIBFILE'!" \
  6.         "Sent in '$0' line '${LINENO}' by '`whoami`' - pwd is '`pwd`'" \
  7.         0 $(tput cols) "$PADDER";
  8.     exit 1
  9. fi

This way, if the library was not found, your script will end with an error and write :

  1. ### ERROR! ###########################################################
  2.     Unable to find required library file 'path/to/piwi-bash-library.sh'!
  3.     Sent in 'current-file.sh' line '0' by 'username' - pwd is '...'
  4. ######################################################################

Developer documentation

Documentation files are included in the doc/ directory of the package.

A quick overview of the whole library methods or variables can be written on screen running (the -v option renders a complete doc with comments for each method) :

  1. ~$ ./path/to/piwi-bash-library.sh (-v) documentation

Demonstration files

A set of test and demonstration files is included in the bin/ directory of the package. These files are not required for a normal usage of the library.

To run one of these tests, just run, depending on your system :

  1. ~$ cd path/to/downloaded/package/piwi-bash-library
  2. ~$ ./bin/file-test.sh
  3. OR
  4. ~$ sh bin/file-test.sh
  5. OR
  6. ~$ bash bin/file-test.sh

You can use the -h option to get help or info :

  1. ~$ ./bin/file-test.sh -h
Voir en ligne : GitHub sources
GNU GPL
Les sources disponibles à l'adresse « https://github.com/atelierspierrot/piwi-bash-library  » sont mises à disposition sous les termes de la licence Licence Publique Générale (GNU General Public License).