function getAPITokens
{
if [ "$#" -ne 4 ]; then
echo "incorrect number of parameters"
exit 1
else
HOST=$1
EMAIL=$2
PASSWORD=$3
LOG=$4
APITOKENS=python /web/tests/selenium-get-info.py -H "$HOST" -AE "$EMAIL" -AP "$PASSWORD" -B /tmp/phantomjs-1.9.2-linux-x86_64/bin/phantomjs -L "$LOG"
echo "$APITOKENS" >> "$LOG"i # newline delimited list
i=0;
for TOKEN in $APITOKENS # convert newlines to array elements
do
ARRAY[$i]=$TOKEN
((i++))
done
echo "${ARRAY[@]}" # return array by printing all elements as a space delimited list
fi
}
TOKENS=( $( getAPITokens "$IPADDRESS" "$ADMINEMAIL" "$ADMINPASSWORD" "/tmp/get-info-selenium.log" ) ) # create array from space delimited string echo "returned array size = ${#TOKENS[@]}"
!/bin/bash
does not handle the case of parameter / well
function listSubDirectories() {
if [ -d $1 ] then DIRECTORY=$1/* for dir in $DIRECTORY do if [ -d $dir ]; then echo $dir fi done else echo "$1 is not a directory." exampleUsage fi }
function exampleUsage() { echo "EXAMPLE: $0 /path/to/target/subdir" }
if [ $# -ne 1 ] then echo "$# is the wrong number of parameters." exampleUsage else array=( $(listSubDirectories $1) ) arraysize=${#array[*]} echo "$arraysize subdirectories found."
if [ $arraysize > 0 ] then echo "${array[@]}"
for element in { 0 $(($arraysize - 1) ) )
do
echo "${array[$element]}"
done
array=( $(listSubDirectories $1) )
fi fi
exit 0