to recode that. You're not using
.
getFileName() {
# usage: getFileName <filename>
local filename=${1##*/}
echo "${filename%.*}"
}
getExtension() { echo "${1##*.}"; } # usage: getExtension <filename>
getPath() { echo "${1%/*}"; } # usage: getPath <filename>
inStr() {
# usage: inStr <char> <string>
local i
for ((i = 0; i < ${#2}; i++)); do
if [[ ${2:i:1} = $1 ]]; then
echo "$i"
fi
done
}
math() {
# usage: math <scale> <expr>
local s=$1
shift
bc <<< "scale = $s;
[email protected]"
}
isRoot() ((! UID)) # usage: if isRoot; then ...; fi
has_read_write_access() [[ -r $1 && -w $1 ]] # usage: if has_read_write_access <filename>; then ...; fi
trimspaces() { echo "${1//${2:-[[:blank:]]}}"; } # usage: trimspaces <text> [ <char> ]
fileExists() [[ -f $1 ]] # usage: if fileExists <filename>; then ...; fi
isNumeric() [[ $1 != *[![:digit:]]* ]] # usage: if isNumeric <string>; then ...; fi
isAlpha() [[ $1 != *[![:alpha:]]* ]] # usage: if isAlpha <string>; then ...; fi
isAlphNum() [[ $1 != *[![:alnum:]]* ]] # usage: if isAlphNum <string>; then ...; fi
initialCaps() {
# usage: initialCaps <string>
example: initialCaps 'john doe'
local a res i
set -f
a=($1)
set +f
for ((i = 0; i < ${#a[@]}; i++)); do
res+="${a[i]^} "
done
echo "${res%[[:blank:]]}"
}
create_user_list() {
# usage: create_user_list
local users u
while IFS=: read -r u _; do
users+=("$u")
done
printf '%s\n' "${users[@]:1}"
}
app_up() { cat - < "$1" "$2"; } # usage: app_up <file_to_append_from> <file_to_append_to>
I didn't recode the other functions, because they rely on external programs that may not be installed on the system being used.