#!/bin/bash # Title: # Version: # Author: Frédéric CHEVALIER # Created in: 2015- # Modified in: # Licence : GPL v3 #======# # Aims # #======# aim="" #==========# # Versions # #==========# # v0.0 - 2015-xx-xx: creation #===========# # Functions # #===========# # Usage message function usage { echo -e " \e[32m ${0##*/} \e[00m -i|--in file -o|--out value -v|--val value -s|--switch -h|--help Aim: $aim Options: -i, --in input file -o, --out name of output file -v, --val value -s, --switch switch -h, --help this message " } # Info message function info { if [[ -t 1 ]] then echo -e "\e[32mInfo:\e[00m $1" else echo -e "Info: $1" fi } # Warning message function warning { if [[ -t 1 ]] then echo -e "\e[33mWarning:\e[00m $1" else echo -e "Warning: $1" fi } # Error message ## usage: error "message" exit_code ## exit code optional (no exit allowing downstream steps) function error { if [[ -t 1 ]] then echo -e "\e[31mError:\e[00m $1" else echo -e "Error: $1" fi if [[ -n $2 ]] then exit $2 fi } # Dependency test function test_dep { which $1 &> /dev/null if [[ $? != 0 ]] then error "Package $1 is needed. Exiting..." 1 fi } #==============# # Dependencies # #==============# test_dep #===========# # Variables # #===========# # Options while [[ $# -gt 0 ]] do case $1 in -i|--in ) input="$2" ; shift 2 while [[ ! -z "$1" && $(echo "$1"\ | grep -qv "^-" ; echo $?) == 0 ]] do input=$(echo "$input" "$1") shift done ;; -o|--out ) output="$2" ; shift 2 ;; -v|--val ) v="$2" ; shift 2 ;; -s|--switch ) switch=1 ; shift ;; -h|--help ) usage ; exit 0 ;; * ) error "Invalid option: $1\n$(usage)" 1 ;; esac done # Check the existence of obligatory options if [[ -z "$input" ]] then error "The option input is required. Exiting...\n$(usage)" 1 fi if [[ -z "$output" ]] then output= fi #============# # Processing # #============# #-------------# # Sub-section # #-------------# exit 0