mardi 9 décembre 2014

Error setting variable to the length of an array in bash


I have the snippet below in a larger script to basically take my balances out of ledger into two arrays so I can print them the way I want to view them.



#!/bin/bash
assets=("assets:checking" "assets:google wallet" "assets:savings" "assets:cash")
assets-bal=()

num=${#assets[@]}
for $i in {0..${num}}
do
read -a tmp <<< `ledger -f finances balance "${assets[${i}]}"`
assets-bal[${i}]=tmp[0]
echo "${assets[${i}]} ${assets-bal[${i}]}"
done


Every time I try runnning the script I get the error:



syntax error near unexpected token `num=${#assets[@]}'
`num=${#assets[@]}'


From my searching, there should be nothing wrong with that line and I just keep coming up empty trying to find a reason why it won't work.


Can anybody point out where I'm wrong?



Aucun commentaire:

Enregistrer un commentaire