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