[fix] fixed substring detection to work in dash
- added missing 'local' keyword to function vars
This commit is contained in:
@@ -46,21 +46,41 @@ function log()
|
||||
# this is a helper function as dash does not support arrays
|
||||
function get_element()
|
||||
{
|
||||
element="$1"
|
||||
seperator="$2"; shift; shift
|
||||
array=$@
|
||||
old_IFS=$IFS
|
||||
local element="$1"; #index to return
|
||||
local seperator="$2"; shift; shift
|
||||
local array=$@
|
||||
local old_IFS=$IFS
|
||||
IFS="$seperator"
|
||||
set -- $array
|
||||
while [ "$element" -gt 0 ]; do
|
||||
shift
|
||||
element=$(( element - 1 ))
|
||||
done
|
||||
result=$1
|
||||
local result=$1
|
||||
IFS=$old_IFS
|
||||
echo $result
|
||||
}
|
||||
|
||||
# helper function to check if a string contains a substring in dash
|
||||
function contains()
|
||||
{
|
||||
local string="$1"
|
||||
local substring="$2"
|
||||
[ -z $(echo "$string" | sed "/$substring/d") ]
|
||||
}
|
||||
# helper function to check if string begins with substring in dash
|
||||
function begins_with()
|
||||
{
|
||||
local string=$1
|
||||
local substring=$2
|
||||
[ -z $(echo "$string" | sed "/^$substring/d") ]
|
||||
}
|
||||
# extra function for readability
|
||||
function has_port()
|
||||
{
|
||||
contains $1 ":"
|
||||
}
|
||||
|
||||
function sleep_wait()
|
||||
{
|
||||
# waiting on sleep to be able to handle SIGTERM
|
||||
@@ -126,7 +146,7 @@ function read_file()
|
||||
|
||||
function rng()
|
||||
{
|
||||
rng_n=$(od -An -N2 -d < /dev/urandom)
|
||||
local rng_n=$(od -An -N2 -d < /dev/urandom)
|
||||
echo $rng_n
|
||||
}
|
||||
|
||||
@@ -140,7 +160,7 @@ function gen_server_config()
|
||||
|
||||
# default to 8080 if server port is undefined
|
||||
local port=":8080";
|
||||
[[ $server == *":"* ]] && port=""
|
||||
has_port $server && port=""
|
||||
|
||||
# no arrays in dash
|
||||
local subdomain=$(get_element $domain_count " " $domain_list)
|
||||
|
||||
Reference in New Issue
Block a user