LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Floating number in linux cell script (https://www.linuxquestions.org/questions/linux-newbie-8/floating-number-in-linux-cell-script-4175486855/)

linuxmantra 12-04-2013 12:14 PM

Floating number in linux cell script
 
---How can I represent floating number in linux cell scripting---
I am working in bash cell
code:

echo "Enter basic salary:"
read basic
echo "HRA `expr 0.2 \* $basic`"

Output shows:
non-numeric arguments.

<< HELP >>

suicidaleggroll 12-04-2013 12:30 PM

Do you mean "shell"? There's no such thing as Linux cell scripting or the bash cell.

The shell can't operate on non-intergers, you'll need to pass it to something that can, such as bc:
Code:

echo "0.2 * $basic" | bc -l

propofol 12-04-2013 10:36 PM

You can also use GNU Octave. Have a look at this tutorial.

As an example, here is a script to convert a Xorg modeline into a framebuffer mode:
Code:

#!/usr/bin/octave -q
bpp = 16;
DCF = sscanf(argv(){1}, "%f");
HR  = sscanf(argv(){2}, "%f");
SH1 = sscanf(argv(){3}, "%f");
SH2 = sscanf(argv(){4}, "%f");
HFL = sscanf(argv(){5}, "%f");
VR  = sscanf(argv(){6}, "%f");
SV1 = sscanf(argv(){7}, "%f");
SV2 = sscanf(argv(){8}, "%f");
VFL = sscanf(argv(){9}, "%f");
pixclock = 1000000 / DCF;
left_margin = HFL - SH2;
right_margin = SH1 - HR;
hsync_len = SH2 - SH1;

# 3) vertical timings:
upper_margin = VFL - SV2;
lower_margin = SV1 - VR;
vsync_len = SV2 - SV1;

RR = DCF / (HFL * VFL) *1e6;
HSF = DCF / HFL * 1e3;

printf("mode \"%dx%d\"\n",HR,VR);
printf("  # D: %3.2f MHz, H: %3.2f kHz, V: %2.2f Hz\n", DCF, HSF, RR);
printf("  geometry %d %d %d %d %d\n", HR, VR, HR, VR, bpp);
printf("  timings %d %d %d %d %d %d %d\n", ...
                                pixclock, left_margin, right_margin, ...
                                upper_margin, lower_margin, ...
                                hsync_len, vsync_len);
printf("endmode\n");



All times are GMT -5. The time now is 07:08 PM.