spark icon indicating copy to clipboard operation
spark copied to clipboard

error on some input numbers with leading zeroes

Open tivasyk opened this issue 8 years ago • 0 comments

when feeding spark with numbers that have leading zeroes bash will eventually report an error when encountering numbers with 8 and 9 (e.g. 08, 09 etc) because bash automatically considers zero-leaded numbers as octals.

possible solution: strip leading zeroes. i have modified the spark() function in my testing spark fork:

    n=${n%%.*}
    # These 3 lines strip leading zeroes and fix error parsing octal-like numbers (008 etc) / tivasyk
    shopt -s extglob
    n=${n##+(0)}
    shopt -u extglob
    # Fix empty n if it was 0
    if [[ $n -eq "" ]]; then
      n=0
    fi

it works, sorry for lame code.

p.s. great script! love it absolutely. i had to add scaling option (e.g. spark -s 100 ) to do things like cpu load gauges for conky etc. to be able to represent percentage data (0..100) in a meaningfull way.

tivasyk avatar Feb 19 '17 16:02 tivasyk