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
|
|
27
by Gustav Hartvigsson
Added copyright information to all files. |
5 |
#
|
6 |
# Authors:
|
|
7 |
# Gustav Hartvigsson 2024
|
|
8 |
# Distributed under the Cool Licence 1.1
|
|
22
by Gustav Hartvigsson
* useful.inc.sh |
9 |
#
|
10 |
# PURPOSE
|
|
11 |
# This file provides usefule bash libary functions.
|
|
12 |
####
|
|
13 |
# Add the following to your script to be able to include it:
|
|
14 |
# __SCRIPT_ROOT=$(dirname $(readlink -f $0))
|
|
15 |
# source $__SCRIPT_ROOT/useful.inc.sh
|
|
16 |
####
|
|
17 |
||
18 |
####
|
|
19 |
# FUNCTION __silent
|
|
20 |
#
|
|
21 |
# PURPOSE
|
|
22 |
# Silent a run command.
|
|
23 |
#
|
|
24 |
# ARGUMENTS
|
|
25 |
# A command and it's arguments.
|
|
26 |
#
|
|
27 |
# RETURNS
|
|
28 |
# Exit code of command.
|
|
29 |
#
|
|
30 |
####
|
|
31 |
function __silent () { |
|
32 |
$@ >> /dev/null 2>&1 |
|
33 |
return $? |
|
34 |
}
|
|
35 |
||
30
by Gustav Hartvigsson
* Fixed useful.inc.sh |
36 |
export -f __silent |
37 |
||
22
by Gustav Hartvigsson
* useful.inc.sh |
38 |
####
|
39 |
# FUNCTION __find_tool
|
|
40 |
#
|
|
41 |
# PURPOSE
|
|
42 |
# checks if a tool (progam) exists.
|
|
43 |
#
|
|
44 |
# NOTE
|
|
45 |
# You need to specify "__SANITY=true" among your globals.
|
|
46 |
####
|
|
47 |
function __find_tool () { |
|
48 |
__silent which $1 |
|
49 |
||
50 |
if [[ $? > 0 ]]; then |
|
51 |
echo " Can't find tool \"${1}\"." |
|
52 |
__SANITY=false |
|
53 |
fi |
|
54 |
}
|
|
30
by Gustav Hartvigsson
* Fixed useful.inc.sh |
55 |
|
56 |
export -f __find_tool |