Adding variables in a unix script

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding variables in a unix script
# 8  
Old 08-27-2009
Tried implementing it but got the same error.

The value "23.45" will be in a variable


total=`echo $a + $(expr b) + $c | bc`

Also tried:
total=`echo $a + $(expr $b) + $c | bc`

# 9  
Old 08-27-2009
post the whole script if you could


value=`echo ""$a"" + $(expr $b) + $g | bc`
echo $value

even this code works for me perfectly....
# 10  
Old 08-27-2009
Following is my code:


#Combined_amount=`echo $(expr $Interchange_value) + $(expr $Assesments_value) + $(expr $Transfees_value) + $(expr $TE_value) | bc`

Combined_amount=`echo ""$Interchange_value"" + $(expr $Assesments_value) + $(expr $Transfees_value) + $(expr $TE_value) | bc`

Both are not working.Here Interchange_value will have the vale "23.45" and others float values.
# 11  
Old 08-27-2009
Combined_amount=`echo ""$Interchange_value"" + $(expr $Assesments_value) + $(expr $Transfees_value) + $(expr $TE_value) | bc`
echo $Combined_amount

output here
+ Interchange_value=23.45
+ Assesments_value=34.65
+ Transfees_value=3
+ TE_value=9
+ + bc
+ expr 34.65
+ expr 3
+ expr 9
+ echo 23.45 + 34.65 + 3 + 9
+ echo 70.10

whatz your unix?
# 12  
Old 08-27-2009
If I make a sample script and use it.It works perfectly fine.
But does not work in my script.

The only difference is that I am getting these variables from a file.:

Interchange_value=`cat $CHASEFILE |head -$line_counter | tail -1 |cut -f13`
Assesments_value=`cat $CHASEFILE |head -$line_counter | tail -1 |cut -f14`

# 13  
Old 08-27-2009
I think you are getting these values with some other characters (may be spaces)
try to echo each one of them
# 14  
Old 08-27-2009
Put some echo statements.:
Interchange_value=`cat $CHASEFILE |head -$line_counter | tail -1 |cut -f13`
echo "Interchange_value is"
echo $Interchange_value
Assesments_value=`cat $CHASEFILE |head -$line_counter | tail -1 |cut -f14`
echo "Assesment value is"
echo $Assesments_value
Transfees_value=`cat $CHASEFILE |head -$line_counter | tail -1 |cut -f15`
echo $Transfees_value
TE_value=`cat $CHASEFILE |head -$line_counter | tail -1 |cut -f16`
echo $TE_value

The output I got:
Interchange_value is
Assesment value is

---------- Post updated at 09:26 AM ---------- Previous update was at 09:20 AM ----------

Tried with

echo "Interchange_value is"
echo "<$Interchange_value>"
Assesments_value=`cat $CHASEFILE |head -$line_counter | tail -1 |cut -f14`
echo "Assesment value is"
echo "<$Assesments_value>"

and got
Interchange_value is
Assesment value is

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Adding same value to variables in does each repetition of command

So, I have this command: mkdir rolled for %%x in (*gif) do convert %%x -roll +2+6 %%x|move %%x rolled I'd like to have the +2 and +6 accumulate here. In each new gif tackled, it should increase by the amount: +2 (for x) and +6 (for y) Is this possible? I'm on Windows, DOS. (0 Replies)
Discussion started by: pasc
0 Replies

2. UNIX for Dummies Questions & Answers

Adding variables to repeating strings

Hello, I want to add a letter to the end of a string if it repeats in a column. so if I have a file like this: DOG001 DOG0023 DOG004 DOG001 DOG0023 DOG001 the output should look like this: DOG001-a DOG0023-a DOG004 DOG001-b (15 Replies)
Discussion started by: verse123
15 Replies

3. Shell Programming and Scripting

Using Datastage environment variables in Unix script

Hi All, I am using ETL tool Datastage and is installed on Linux environment. Few environment variables are set in datastage. Now my requirement is to use those environment variables in a unix script. Is there any option I can do it? Sugeestions from people working on datastage and linux... (1 Reply)
Discussion started by: bghosh
1 Replies

4. UNIX for Dummies Questions & Answers

Define variables with UNIX script

oopps! I Meant "Define Variables within a UNIX Script" What would be the best way to define a variable in a unix shell script so anyone who views this script doesn't know what value is assigned to that variable. some other location... a="/usr/lib/fileA" Unix script... sed... (5 Replies)
Discussion started by: macastor
5 Replies

5. Shell Programming and Scripting

Adding Variables

Hi. I have a for loop that I use to extract integer values in a shell script (ksh). Now, I would like to add the values. My preference, from my c programming days, would be to do something like the commented out line below in the for loop. However, this is not recognised. So I use the line... (2 Replies)
Discussion started by: mikem22
2 Replies

6. Solaris

Creating script adding 3 different variables in 3 columns

I have 3 variables with different information.. they look like this (row-wise aswell): Variable1 = Roland Kalle Dalius Variable2 = ake123 ler321 kaf434 Variable3 = Richardsen Sworden Lokthar How can I sort them by variable3 alphabetical and add them into the same output so... (0 Replies)
Discussion started by: Prantare
0 Replies

7. Shell Programming and Scripting

Simple unix variables in script

I'm creating a script that asks a user for a variable ex read filename; read numberinput; I also have a bunch of files named file.0 file.1 ... file.55 I'm trying to delete all files (if they exist) about file.$numberinput. Can someone help me out on how to include the variable as part... (6 Replies)
Discussion started by: jenix4545
6 Replies

8. Shell Programming and Scripting

Pass variables to a Unix script from a file

Hi, I am running a Java program from a unix script. I need to pass a variable to the Java code from a file. Here are teh details: cat Parm <<this is my Parameter file>> queuename=queue1 and my shell script is : #!/bin/ksh . ./Parm /opt/java1.5/bin/java -classpath ./java.jar... (1 Reply)
Discussion started by: sangharsh
1 Replies

9. Programming

adding variables for, for loop

I have a structure which contains n number of elements. For example: stFruits : apple, grapes, strawberry, pear, kiwi, melon, papaya, mango, orange, sweetlime ..... etc Now i have to write a for loop as follows: int i; int j; and so... (3 Replies)
Discussion started by: jazz
3 Replies
Login or Register to Ask a Question