Sunday, March 6, 2011

FOREX : week 28 February - 4 March 2011

AUD_USD
EUR_CHF
EUR_GBP
EUR_JPY
EUR_USD
GBP_JPY
GBP_USD
NZD_USD
USD_CAD
USD_CHF
USD_JPY

FOREX : week 21 February - 25 February 2011

AUD_USD
EUR_CHF
EUR_GBP
EUR_JPY
EUR_USD
GBP_JPY
GBP_USD
NZD_USD
USD_CAD
USD_CHF
USD_JPY

Thursday, March 3, 2011

BASH : Combine ARRAYS

#!/bin/sh

COUNTRY=( "Austria" "Finland" "USA")
CAPITAL=( "Viena" "Helsinky" "New York")

n=${#COUNTRY[@]} #num elements in array COUNTRY

for (( i=0; i<n; i++ ))
do
COMB[$i]=${COUNTRY[$i]}"["${CAPITAL[$i]}"]"
echo ${COMB[$i]}
done


ResultsAustria[Viena]
Finland[Helsinky]
USA[New York]

BASH : Array operations


${arr[*]}         # All of the items in the array
${!arr[*]}        # All of the indexes in the array
${#arr[*]}        # Number of items in the array
${#arr[0]}        # Length of item zero
#!/bin/bash

array=(one two three four [5]=five)

echo "Array size: ${#array[*]}"

echo "Array items:"
for item in ${array[*]}
do
    printf "   %s\n" $item
done

echo "Array indexes:"
for index in ${!array[*]}
do
    printf "   %d\n" $index
done

echo "Array items and indexes:"
for index in ${!array[*]}
do
    printf "%4d: %s\n" $index ${array[$index]}
done
Running it produces the following output:
Array size: 5
Array items:
   one
   two
   three
   four
   five
Array indexes:
   0
   1
   2
   3
   5
Array items and indexes:
   0: one
   1: two
   2: three
   3: four
   5: five
#!/bin/bash

array=("first item" "second item" "third" "item")

echo "Number of items in original array: ${#array[*]}"
for ix in ${!array[*]}
do
    printf "   %s\n" "${array[$ix]}"
done
echo

arr=(${array[*]})
echo "After unquoted expansion: ${#arr[*]}"
for ix in ${!arr[*]}
do
    printf "   %s\n" "${arr[$ix]}"
done
echo

arr=("${array[*]}")
echo "After * quoted expansion: ${#arr[*]}"
for ix in ${!arr[*]}
do
    printf "   %s\n" "${arr[$ix]}"
done
echo

arr=("${array[@]}")
echo "After @ quoted expansion: ${#arr[*]}"
for ix in ${!arr[*]}
do
    printf "   %s\n" "${arr[$ix]}"
done
When run it outputs:
Number of items in original array: 4
   first item
   second item
   third
   item

After unquoted expansion: 6
   first
   item
   second
   item
   third
   item

After * quoted expansion: 1
   first item second item third item

After @ quoted expansion: 4
   first item
   second item
   third
   item

BASH : Pass arrays as argument

#!/bin/bash


array1=(1 2 3 4 5 6 7 8 9)
array2=(10 20 30 40 50 60 70 80 90)


printArrays()
{
    declare -a argAry1=("${!1}")
    echo "${argAry1[@]}"


    declare -a argAry2=("${!2}")
    echo "${argAry2[@]}"
}


printArrays array1[@] array2[@]

BASH : Pass array as argument

array2=(10 20 30 40 50 60 70 80 90)
function ParseArray
{
for i in ${@}
do
echo $i
done
}


ParseArray ${array2[@]}