Sponsored Content
Top Forums Shell Programming and Scripting Assigning bc output to a variable Post 302871881 by pina on Thursday 7th of November 2013 07:11:41 AM
Old 11-07-2013
Assigning bc output to a variable

I'm converting decimal to integer with bc, and I'd like to assign the integer output from bc to a variable 'val'.

E.g. In the code below: If b is 5000.000, lines 6 and 8 will output:
5000
(5000.000+0.5)/1 | bc

I'd like val to take the value 5000 though, rather than 5000.000

Does someone have any idea how to do that?
Code:
#! /bin/bash

while read b
do

    echo "($b+0.5)/1" | bc        # line 6 - works
    val= "($b+0.5)/1 | bc"        # line 7 - doesn't work
    echo $val                          # line 8

done < infile


Last edited by Franklin52; 11-07-2013 at 08:20 AM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assigning output of command to a variable

Hi, I'm trying to assign the output of a command to a variable and then concat it with another string, however, it keeps overwriting the original string instead of adding on to the end of the string. Contents of test.txt --> This is a test var1="`head -n 1 test.txt`" echo $var1 (This is a... (5 Replies)
Discussion started by: oma04
5 Replies

2. Shell Programming and Scripting

assigning command output to a shell variable

I have the sql file cde.sql with the below contents: abcdefghij abcwhendefothers sdfghj when no one else when others wwhen%others exception when others Now I want to search for the strings containing when others together and ceck whether that does not occur more than once in the... (2 Replies)
Discussion started by: kprattip
2 Replies

3. Shell Programming and Scripting

assigning nawk output to shell variable

Hello friends, I doing the follwing script , but found problem to store it to a shell variable. #! /bin/sh for temp in `find ./dat/vector/ -name '*.file'` do echo $temp nawk -v temp=$temp 'BEGIN{ split(temp, a,"\/"); print a}' done output: ./dat/vector/drf_all_002.file... (6 Replies)
Discussion started by: user_prady
6 Replies

4. Shell Programming and Scripting

Assigning output of command to a variable in shell

hi, I want to assign find command result into some temporary variable: jarPath= find /opt/lotus/notes/ -name $jarFile cho "the jar path $jarPath" where jarPath is temporary variable. Can anybody help on this. Thanks in advance ----Sankar (6 Replies)
Discussion started by: sankar reddy
6 Replies

5. Shell Programming and Scripting

Assigning output to a variable

I am new to unix shell scripting. I was trying to convert each lines in a file to upper case. I know how to convert the whole file. But here i have to do line by line. I am getting it in the below mentioned script #!/bin/bash #converting lower to upper in a file #tr "" "" <file1... (3 Replies)
Discussion started by: jpmena
3 Replies

6. Shell Programming and Scripting

Assigning output of a command to variable

When I run time -p <command>, it outputs: real X.XX user X.XX sys X.XXwhere X.XX is seconds. How I can take just that first number output, the seconds of real time, and assign that to a variable? (9 Replies)
Discussion started by: jeriryan87
9 Replies

7. Shell Programming and Scripting

assigning SED output to a variable = trouble!

i'm on a Mac running BSD unix. i have a script in which i ask the user to input the name of a mounted volume. i then call SED to substitute backslashes and spaces in place of the spaces. that looks like this: echo "Enter the name of the volume" read Volume echo "You've chosen \"$Volume\""... (7 Replies)
Discussion started by: hungryd
7 Replies

8. Shell Programming and Scripting

Piping and assigning output to a variable in Perl

Hi All, I am trying to convert the below Csh code into Perl. But i have the following error. Can any expert help ? Error: ls: *tac: No such file or directory Csh set $ST_file = `ls -rt *$testid*st*|tail -1`; Perl my $ST_file = `ls -rt *$testid*st*|tail -1`; (10 Replies)
Discussion started by: Raynon
10 Replies

9. Shell Programming and Scripting

Assigning output from awk to variable

I have a script whose contents are as below result= awk 's=100 END {print s }' echo "The result is" $result The desired output is The result is 100 My script is running without exiting and i am also not getting the desired output. Please help (5 Replies)
Discussion started by: bk_12345
5 Replies

10. Shell Programming and Scripting

Expect - assigning UNIX command output to a variable

Hi, I'm writing a script that connects through ssh (using "expect") and then is supposed to find whether a process on that remote machine is running or not. Here's my code (user, host and password are obviously replaced with real values in actual script): #!/usr/bin/expect set timeout 1... (3 Replies)
Discussion started by: oseri
3 Replies
IOASIC(4)						   BSD Kernel Interfaces Manual 						 IOASIC(4)

NAME
ioasic -- baseboard IO control ASIC for DEC TURBOchannel systems SYNOPSIS
ioasic0 at tc? slot ? offset ? DESCRIPTION
The ioasic driver provides support for the DEC proprietary IOCTL ASIC found on all DEC TURBOchannel machines with MIPS (DECstation 5000 series, excluding the 5000/200) and Alpha (3000-series) processors. On these machines (including the 5000/200), all baseboard devices should be configured as children of the ioasic device. The ioasic provides hardware DMA channels and interrupt support for several baseboard devices, including one asc SCSI device with a scat- ter/gather DMA channel, an mc146818-compatible mcclock, an Am7930 audio device bba, one or two scc two-port serial devices, and a AMD 7990 LANCE le Ethernet interface. The ioasic is also used for the floppy-disc drive and audio/ISDN hardware on the Personal DECstation and audio-equipped TURBOchannel Alphas, where the ioasic hardware provides a scatter-gather DMA channel between the 16-bit device and the 32-bit tc DMA address space. Support for scatter-gather DMA eliminates the need for additional copying. A baseboard asc SCSI adaptor attached to an ioasic will give slightly better performance than its tc counterpart. SEE ALSO
asc(4), bba(4), intro(4), le(4), mcclock(4), scc(4), tc(4) HISTORY
The ioasic driver first appeared in NetBSD 1.1, derived from DECstation boot-time configuration code in 4.4BSD. BUGS
The DECstation 5000/200 does not actually have an IOASIC chip, but for consistency it must be configured as if it did. BSD
September 12, 1996 BSD
All times are GMT -4. The time now is 10:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy