bzr branch
http://gegoxaren.bato24.eu/bzr/useful/trunk-1
22
by Gustav Hartvigsson
* useful.inc.sh |
1 |
#!/usr/bin/env bash
|
2 |
||
3 |
####
|
|
4 |
# FILE NAME useful.inc.sh
|
|
5 |
#
|
|
6 |
# PURPOSE
|
|
7 |
# This file provides usefule bash libary functions.
|
|
8 |
####
|
|
9 |
# Add the following to your script to be able to include it:
|
|
10 |
# __SCRIPT_ROOT=$(dirname $(readlink -f $0))
|
|
11 |
# source $__SCRIPT_ROOT/useful.inc.sh
|
|
12 |
####
|
|
13 |
||
14 |
####
|
|
15 |
# FUNCTION __silent
|
|
16 |
#
|
|
17 |
# PURPOSE
|
|
18 |
# Silent a run command.
|
|
19 |
#
|
|
20 |
# ARGUMENTS
|
|
21 |
# A command and it's arguments.
|
|
22 |
#
|
|
23 |
# RETURNS
|
|
24 |
# Exit code of command.
|
|
25 |
#
|
|
26 |
####
|
|
27 |
function __silent () { |
|
28 |
$@ >> /dev/null 2>&1 |
|
29 |
return $? |
|
30 |
}
|
|
31 |
||
32 |
####
|
|
33 |
# FUNCTION __find_tool
|
|
34 |
#
|
|
35 |
# PURPOSE
|
|
36 |
# checks if a tool (progam) exists.
|
|
37 |
#
|
|
38 |
# NOTE
|
|
39 |
# You need to specify "__SANITY=true" among your globals.
|
|
40 |
####
|
|
41 |
function __find_tool () { |
|
42 |
__silent which $1 |
|
43 |
||
44 |
if [[ $? > 0 ]]; then |
|
45 |
echo " Can't find tool \"${1}\"." |
|
46 |
__SANITY=false |
|
47 |
fi |
|
48 |
}
|