+#!/usr/bin/bash
+
########################################################
# UTILITY FUNCTIONS
########################################################
function join {
local d=$1
shift
- echo -n "$1"
+ echo -n "${1}"
shift
printf "%s" "${@/#/$d}"
}
# 1) element to remove
# 2-..) array
function remove_element {
- remove=${1}
+ local remove=${1}
shift
- new_array=()
- for elem in ${@}; do
- if [[ ${elem} != ${remove} ]]; then
+ local new_array=()
+ for elem in "${@}"; do
+ if [[ ${elem} != "${remove}" ]]; then
new_array+=("${elem}")
fi
done
- join ' ' ${new_array[@]}
+ join ' ' "${new_array[@]}"
}
# Workaround for 'sdb shell' inability to propagate error codes
function sdb_shell_verbose {
set +e
- error_str='SDB_ERROR'
- cmd="${SDB_CMD[@]} shell ${@}"
- output=$(command ${cmd} '||' 'echo' "${error_str}")
+ local error_str='SDB_ERROR'
+ local cmd=("${SDB_CMD[@]}" shell "${@}")
+ local output
+ output=$(command "${cmd[@]}" '||' 'echo' "${error_str}")
echo "${output}" | grep "${error_str}" >/dev/null
if [[ $? -eq 0 ]]; then
# Silent version
function sdb_shell {
# print the sdb command
- echo "${SDB_CMD[@]} shell ${@}"
+ echo "${SDB_CMD[*]} shell ${*}"
- sdb_shell_verbose ${@} >/dev/null
+ sdb_shell_verbose "${@}" >/dev/null
}
# Checks the device architecture
# Exports all current environment
function export_all {
- `echo "export" $((set -o posix ; set) | awk -F "=" 'BEGIN{ORS=" "}1 $1~/[a-zA-Z]/ {print $1}')`
+ export $( (set -o posix ; set) | awk -F "=" 'BEGIN{ORS=" "}1 $1~/[a-zA-Z]/ {print $1}' )
export -f join
export -f pushd
export -f popd