математические операции из элементов массива в сценарии bash [закрыты]

Используя Ubuntu 13.10, bash и zenity, я создаю простую утилиту чековой книжки. В приведенном ниже коде, раздел со всеми комментариями математических команд - это те, которые я пробовал. Существует также проблема с частью значения справа от десятичной точки, о чем свидетельствует следующее сообщение об ошибке: / home / larry / bin / chkbk: строка 144: let: tmp [7] = 163.41-40.00 + 0 : синтаксическая ошибка: неверный арифметический оператор (токен ошибки «.41-40.00 + 0»). Я был бы признателен за любую помощь. спасибо ....

#! /bin/bash
#
#####################################
#  Check Book Utility               #
#  --using chkbk as program         #
#  --using chkdat as data file      #
#  --using chkhlp as help file      #
#####################################
#
##################
#  Declarations  #
##################
declare -a chk=()
declare -a hlp=()
declare -a tmp=()

declare -r patdat="/home/larry/bin/chkdat"
declare -r pathlp="/home/larry/bin/chkhlp"
#   end declarations

###############
#  Functions  #
###############
loadfiles() {
zenity --progress\
    --title=Initializing....\
    --no-cancel\
    --text='Loading....'\
    --pulsate\
    --auto-close\
    --width=250\
    --height=50\
    --timeout=3

    if [ -e ~/bin/chkdat ];
      then
        let i=1
        while IFS=$'\n' read -r line_data; do
            chk[i]="${line_data}"
            ((++i))
        done < ~/bin/chkdat;
    else
        > ~/bin/addrdata;
    fi

    if [ -e ~/bin/chkhlp ];
      then
        let i=1
        while IFS=$'\n' read -r line_data; do
            hlp[i]="${line_data}"
            ((++i))
        done < ~/bin/chkhlp;
    else
        > ~/bin/chkhlp;
    fi
}   # end loadfiles function

main() {
ans=$(zenity  --list\
    --radiolist\
    --text "Select:"\
    --width 300\
    --height 250\
    --title "Main Menu"\
    --column "Choice"\
    --column "Action"\
    FALSE "Add New Transaction"\
    FALSE "Edit Transaction"\
    FALSE "Search Transactions"\
    FALSE "View Help"\
    TRUE "Exit Program"\
    --hide-header)  # this must be at the bottom

    case $ans in
        "Add New Transaction")
            d=$(zenity --calendar\
            --title "Add Transaction "\
            --text "Click OK for today's date"\
            --date-format='%d %b %Y')
            tmp[1]=${d}
            a=$(zenity --list --radiolist\
                --title "Add Transaction"\
                --text "Account Codes"\
                --column "Choice"\
                --column "Action"\
                --width 300\
                --height 500\
                FALSE "000 Null Account"\
                TRUE "101 SSI"\
                FALSE "102 SSA"\
                FALSE "103 Gifts"\
                FALSE "104 Other"\
                FALSE "201 Rent"\
                FALSE "202 Electric"\
                FALSE "203 General"\
                FALSE "204 Food"\
                FALSE "205 Clothing"\
                FALSE "206 Pet Care"\
                FALSE "207 Charity"\
                FALSE "208 Health Care"\
                FALSE "209 Transportation"\
                --hide-header)
                tmp[2]=${a:0:3}
            m=$(zenity --list --radiolist\
                --title "Add Transaction"\
                --text "Method Codes"\
                --column "Choice"\
                --column "Action"\
                --width 300\
                --height 250\
                TRUE "bb Beginning Balance"\
                FALSE "ck Check"\
                FALSE "cs Cash"\
                FALSE "dc Debit Card"\
                FALSE "dd Direct Deposit"\
                --hide-header)
                tmp[3]=${m:0:2}

            v=$(zenity --entry\
                --title "Add Transaction"\
                --text "Enter Payee / Payor"\
                --width 400)
                tmp[4]=${v}

            t=$(zenity --entry\
                --title "Add Transaction"\
                --text "Enter amount of transaction:")
            if [ ${a:0:3} -lt 200 ]; then 
                tmp[5]=0
                tmp[6]=${t};
            else 
                tmp[5]=${t}
                tmp[6]=0;
            fi

        if [ ${a:0:1} -eq 0 ]; then
            tmp[7]=${tmp[6]}
        else # [ ${a:0:1} -gt 0 ]; then
            #echo "tmp[7] = chk[7] - tmp[5] + tmp[6]"
            #tmp[7]=`expr ${chk[7]} - ${tmp[5]} + ${tmp[6]}`
            #$(( tmp[7] = ${chk[7]} - ${tmp[5]} + ${tmp[6]} ))
            let x=${#chk[@]}-1
            #$(( tmp[7] = chk[x] - tmp[5] + tmp[6] ))
            #let tmp[7]="${chk[x]}"
            #let tmp[7]="${tmp[7]}"-"${tmp[5]}"
            #let tmp[7]="${tmp[7]}"+"${tmp[6]}"
            #let tmp[7] = chk[7] - tmp[5] + tmp[6]
            #tmp[7]=${chk[x]}-${tmp[5]}+${tmp[6]}
            #tmp[7]=chk[x]-tmp[5]+tmp[6]
            let tmp[7]=chk[x]-tmp[5]+tmp[6]
        fi;

        zenity --question\
            --title="Add Transaction"\n\
            --text="You have entered:\n\
               Date:  ${d}\n\
            Account:  ${a}\n\
             Method:  ${m}\n\
             Vendor:  ${v}\n\
            Amounmt:  ${t}\n\n\
            Are these entries correct?"
        case $? in
            0)
                for i in $(seq 1 7); do
                    chk=( "${chk[@]}" "${tmp[i]}" )
                    echo "${tmp[i]}" >> ~/bin/chkdat
                done
                main
                ;;
            1)  
                main;;
        esac
        ;;

         "Edit Transaction")
            let x=${#chk[@]}
            ret=$(for i in $(seq 0 $x)
                do
                    echo ${chk[i]}
                done | yad --list\
                    --title "  Checkbook"\
                    --text "  Edit Check Records:"\
                    --column Date\
                    --column Account\
                    --column Method\
                    --column 'Pay To/From'\
                    --column Debit\
                    --column Credit\
                    --column Balance\
                    --width 800\
                    --height 450\
                    --center\
                    --editable)
            main
            ;;
         "Search Transactions")
            let x=${#chk[@]}
             ret=$(for i in $(seq 0 $x)
                do
                    echo ${chk[i]}
                done | yad --list\
                    --title "  Checkbook"\
                    --text "  View Check Records:"\
                    --column Date\
                    --column Account\
                    --column Method\
                    --column 'Pay To/From'\
                    --column Debit\
                    --column Credit\
                    --column Balance\
                    --width 800\
                    --height 450\
                    --center)
            main
            ;;
         "View Help")
            zenity --text-info\
            --title "Checkbook Help"\
            --filename=/home/larry/bin/chkhlp\
            --width=450\
            --height=450;
            main
            ;;
         "Exit Program")
            ;;
    esac
}   # end main function
#   end functions

##################
#  Main Program  #
##################
echo -en "\e]0;  Check Book \007"
echo -en "\e[0;46m"; clear
yad --text-info\
    --timeout=5\
    --borders=0\
    --width=300\
    --height=50\
    --center\
    --no-buttons\
    --fixed\
    --title=Welcome\
    --text="Larry\'s Checkbook\n\n version 1.0.0\n\n 2014 Avdiel Data Solutions"\
    --text-align=center
loadfiles
main
echo -en "\e]0;  Larry's Bash \007"
reset
#   end of program
1
задан 14 February 2014 в 15:29

0 ответов

Другие вопросы по тегам:

Похожие вопросы: