Sponsored Content
Top Forums Shell Programming and Scripting Adding variables in a unix script Post 302348036 by akashtcs on Thursday 27th of August 2009 07:55:39 AM
Old 08-27-2009
Thanks a lot....Smilie

total=`echo $numone + $numtwo | bc`

worked fine.

There is also one more prob......The variable sometimes contains "" attached to it also eg "23.45".
How to handle this in the addition?It is throwing an error"syntax error on line 1 stdin"
Smilie
 

9 More Discussions You Might Find Interesting

1. 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; j=stFruits.apple+stFruits.grapes+stFruits.pear+.... and so... (3 Replies)
Discussion started by: jazz
3 Replies

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
FGETS(3)								 1								  FGETS(3)

fgets - Gets line from file pointer

SYNOPSIS
string fgets (resource $handle, [int $length]) DESCRIPTION
Gets a line from file pointer. PARAMETERS
o $handle -The file pointer must be valid, and must point to a file successfully opened by fopen(3) or fsockopen(3) (and not yet closed by fclose(3)). o $length - Reading ends when $length - 1 bytes have been read, or a newline (which is included in the return value), or an EOF (whichever comes first). If no length is specified, it will keep reading from the stream until it reaches the end of the line. Note Until PHP 4.3.0, omitting it would assume 1024 as the line length. If the majority of the lines in the file are all larger than 8KB, it is more resource efficient for your script to specify the maximum line length. RETURN VALUES
Returns a string of up to $length - 1 bytes read from the file pointed to by $handle. If there is no more data to read in the file pointer, then FALSE is returned. If an error occurs, FALSE is returned. CHANGELOG
+--------+-----------------------------+ |Version | | | | | | | Description | | | | +--------+-----------------------------+ | 4.3.0 | | | | | | | fgets(3) is now binary safe | | | | +--------+-----------------------------+ EXAMPLES
Example #1 Reading a file line by line <?php $handle = @fopen("/tmp/inputfile.txt", "r"); if ($handle) { while (($buffer = fgets($handle, 4096)) !== false) { echo $buffer; } if (!feof($handle)) { echo "Error: unexpected fgets() fail "; } fclose($handle); } ?> NOTES
Note If PHP is not properly recognizing the line endings when reading files either on or created by a Macintosh computer, enabling the auto_detect_line_endings run-time configuration option may help resolve the problem. Note People used to the 'C' semantics of fgets(3) should note the difference in how EOF is returned. SEE ALSO
fgetss(3), fread(3), fgetc(3), stream_get_line(3), fopen(3), popen(3), fsockopen(3), stream_set_timeout(3). PHP Documentation Group FGETS(3)
All times are GMT -4. The time now is 07:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy