#!/bin/bash
function thous {
numfmt --g $1 | sed 's/,/./g;s/@//g'
}
aa="1,235"
bb="5,22"
cc=$(echo "$aa + $bb" | bc)
#1
echo $aa
#2
echo $bb
#3
echo $(thous "$cc")
#4
echo "SKIP"
exit
What shown
(standard_in) 1: parse error
(standard_in) 1: parse error
1,235
5,22
What I want
(standard_in) 1: parse error
(standard_in) 1: parse error
1,235
5,22
(some error or nothing at all)
SKIP
If you try to compile this bash shell code, you will got stuck on #3. So, How to tell the terminal, to ignore whatever that cannot be processed and just go on the next process?
Please do tell me if the question is unclear, Thank you
thous
is trying to do. Thousand separators and decimal radix characters are locale dependant. What iss/,/./g
meant to do? Change the decimal radix from,
to.
? Change the thousand separator from,
to.
? Why removing the@
s. Where would they come from? – Stéphane Chazelas Mar 31 '22 at 08:34export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8
on top of the script. I'm using numfmt to format the thousand separator, somehow my bash doesn't accept any other locale other than US, so, in order to change the number from 1,000.00 to my actual local thousand separator which is 1.000,00, that's what thesed
does. – CuriousNewbie Mar 31 '22 at 09:05,
and.
would be done withtr ,. .,
. – Stéphane Chazelas Mar 31 '22 at 09:33