I read a billion of discussion about this but still have confused thoughts. I just need to use bash to calculate some parameters, and for this operation I need to get the integer part of a float operation. I tried many ways, but each time I get some errors. Here is the last one:
fkeypar "ex1.fef[1]" TSTARTI #### fkeypar is an external command to get some values to assign to the subsequent variables
t0i="$(expr $(pget fkeypar value) - 11544)"
fkeypar "ex1lc.fits[2]" TELAPSE
lengthini=`pget fkeypar value`
fkeypar "ex7lc.fits[2]" TSTOP
lengthfin=`pget fkeypar value`
fkeypar "ex1lc.fits[2]" TSTART
ijd=`pget fkeypar value`
i=$(echo "scale=0; ($ijd - $t0i)/$period + 1" | bc)
ifin=$(echo "scale=0; ($lengthfin - $ijd)/$period + 1" | bc)
echo $i
for ((n=$i; n<=$ifin; n++))
do
echo $n
where all the parameters in i
and ifin
are defined. This code is within a for
cycle, and it returns me an error (many times):
./gti_user_tot: line 34: ((: n=: syntax error: operand expected (error token is "=")
bc: symbol lookup error: /science/heasoft-6.14/x86_64-unknown-linux-gnu-libc2.9/lib/libreadline.so.6: undefined symbol: PC
bc: symbol lookup error: /science/heasoft-6.14/x86_64-unknown-linux-gnu-libc2.9/lib/libreadline.so.6: undefined symbol: PC
./gti_user_tot: line 34: ((: n=: syntax error: operand expected (error token is "=")
The echo $i
seems ignored, the for
cycle over n
has some problems.
I could avoid bc
but I can't find a stable way to workaround.
bash
to run your script? – Greg Hewgill Jun 26 at 2:55#!/bin/bash
– Py-ser Jun 26 at 2:57echo '1.1111 1.1111 +p' | dc | sed 's/\..*//'
– mikeserv Jun 26 at 2:59