Sponsored Content
Top Forums Shell Programming and Scripting Using IF statements with maths where the input is not an integer Post 302546817 by yazu on Friday 12th of August 2011 08:40:33 AM
Old 08-12-2011
Try string comparison:
Code:
if [ "$input" != "0" ]; then
...


Last edited by yazu; 08-12-2011 at 10:18 AM.. Reason: double posting
This User Gave Thanks to yazu For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with Maths

Heres a script i wrote as a bit of practise. What it does is insert a line in the middle of a file. The line being $1 and the file being $2 #!/bin/bash rm tempfile touch tempfile count=1 linenum= `wc -l < $2` if then echo $1 >> $2 else even=`expr "$linenum" % 2` if then... (3 Replies)
Discussion started by: Quesa
3 Replies

2. Shell Programming and Scripting

isql input file with multiple sql statements

I've got: isql -U $USERID -S $SERVER -D $DATABASE -i inputfile.sql -o outputfile.txt in inputfile I have: go sql#1 go sql#2 go sql#3 go I also tried without "go" and with";" instead which did not work SQL statements will work if I paste them directly into the script and use EOF ... (0 Replies)
Discussion started by: Cailet
0 Replies

3. Shell Programming and Scripting

Perl - maths equation - need help

if input to the perl program is ' ( p * ((a+b) * (c+d))) + q ' it shuld give the output as ' pac + pad + pbc + pbd + q ' .can anyone suggest a way to do this ? (7 Replies)
Discussion started by: Anuj8584
7 Replies

4. Programming

How i can read a long integer from standar input and a string with as many characters as specified..

how i can read a long integer from standar input and a string with as many characters as specified in the number? i thing that i must use the read command ofcourse.... (6 Replies)
Discussion started by: aintour
6 Replies

5. Shell Programming and Scripting

Maths with variables

Hello, I'm trying to write a while loop for a decimal value in tcsh which I know can't be done. Instead I want my increments to be one order of magnitude too large and then divide it by 10 when I use the variable. However, I don't know how to divide my variable and set it as another. set... (1 Reply)
Discussion started by: DFr0st
1 Replies

6. UNIX for Dummies Questions & Answers

Check if input is an integer or a floating point?

Hiii I actually intent to check the integer or floating point number input by user i.e. 23, 100, 55.25, 12.50 ..etc. However, when someone input strings or alpha character, my program has to show invalid input.!! Is there any Unix shell script syntax can help me to check ? Thanking you (2 Replies)
Discussion started by: krishnampkkm
2 Replies

7. Programming

I don't know how to replace input char with appropriate integer

Hi guys, I asked for help on programming forums and no one didn't helped me so I ask for help here. I am playing with some tasks from my book and I can't figure where did I get wrong. From the first program I get a blank screen, program won't generate 10*10 matrix. And second problem is I... (6 Replies)
Discussion started by: solaris_user
6 Replies

8. Shell Programming and Scripting

Simple maths calculator loop.

Hi, I am trying to make a maths calculator that: 1. Prompts the user for a number. 2. Prompts the user for an operation (add, subtract, divide or multiply) 3. Prompts the user for a number. 4. Prompts the user for another operation (same as above) OR the option to get the result for the... (4 Replies)
Discussion started by: johnthebaptist
4 Replies

9. Shell Programming and Scripting

Maths in shell scripts

Hi, Need help on this. I need to increment a variable by 1 but retain as 2 characters. I am using expr to do additions: NEWSERIAL=`expr $SERIAL + 1` $SERIAL can range from 01-99. After adding "1", I need the result to be 2 characters, eg: 02+1 = 03. By default expr will truncate the... (4 Replies)
Discussion started by: vchee
4 Replies

10. Shell Programming and Scripting

Calculate the constant e to 14+ decimal places using integer maths.

Hi guys... I am loving this integer maths thing. 64 bit systems are certainly easier than 32 bit, but hey, I don't intend to leave out my fav' platform. Using one of the 'Brothers' methods, URL inside the code. #!/bin/sh # # #!/usr/local/bin/dash # e_constant.sh # Brother's formula . #... (2 Replies)
Discussion started by: wisecracker
2 Replies
pgm(5)								File Formats Manual							    pgm(5)

NAME
pgm - portable graymap file format DESCRIPTION
The PGM format is a lowest common denominator grayscale file format. It is designed to be extremely easy to learn and write programs for. (It's so simple that most people will simply reverse engineer it because it's easier than reading this specification). A PGM image represents a grayscale graphic image. There are many psueudo-PGM formats in use where everything is as specified herein except for the meaning of individual pixel values. For most purposes, a PGM image can just be thought of an array of arbitrary integers, and all the programs in the world that think they're processing a grayscale image can easily be tricked into processing something else. One official variant of PGM is the transparency mask. A transparency mask in Netpbm is represented by a PGM image, except that in place of pixel intensities, there are opaqueness values. See below. The format definition is as follows. A PGM file consists of a sequence of one or more PGM images. There are no data, delimiters, or padding before, after, or between images. Each PGM image consists of the following: - A "magic number" for identifying the file type. A pgm image's magic number is the two characters "P5". - Whitespace (blanks, TABs, CRs, LFs). - A width, formatted as ASCII characters in decimal. - Whitespace. - A height, again in ASCII decimal. - Whitespace. - The maximum gray value (Maxval), again in ASCII decimal. Must be less than 65536. - Newline or other single whitespace character. - A raster of Width * Height gray values, proceeding through the image in normal English reading order. Each gray value is a number from 0 through Maxval, with 0 being black and Maxval being white. Each gray value is represented in pure binary by either 1 or 2 bytes. If the Maxval is less than 256, it is 1 byte. Otherwise, it is 2 bytes. The most significant byte is first. - Each gray value is a number proportional to the intensity of the pixel, adjusted by the CIE Rec. 709 gamma transfer function. (That transfer function specifies a gamma number of 2.2 and has a linear section for small intensities). A value of zero is therefore black. A value of Maxval represents CIE D65 white and the most intense value in the image and any other image to which the image might be com- pared. - Note that a common variation on the PGM format is to have the gray value be "linear," i.e. as specified above except without the gamma adjustment. pnmgamma takes such a PGM variant as input and produces a true PGM as output. - In the transparency mask variation on PGM, the value represents opaqueness. It is proportional to the fraction of intensity of a pixel that would show in place of an underlying pixel, with the same gamma transfer function mentioned above applied. So what normally means white represents total opaqueness and what normally means black represents total transparency. In between, you would compute the inten- sity of a composite pixel of an "under" and "over" pixel as under * (1-(alpha/alpha_maxval)) + over * (alpha/alpha_maxval).< - Characters from a "#" to the next end-of-line, before the maxval line, are comments and are ignored. Note that you can use pnmdepth To convert between a the format with 1 byte per gray value and the one with 2 bytes per gray value. There is actually another version of the PGM format that is fairly rare: "plain" PGM format. The format above, which generally considered the normal one, is known as the "raw" PGM format. See pbm(5) for some commentary on how plain and raw formats relate to one another. The difference in the plain format is: - There is exactly one image in a file. - The magic number is P2 instead of P5. - Each pixel in the raster is represented as an ASCII decimal number (of arbitrary size). - Each pixel in the raster has white space before and after it. There must be at least one character of white space between any two pix- els, but there is no maximum. - No line should be longer than 70 characters. Here is an example of a small graymap in this format: P2 # feep.pgm 24 7 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0 0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0 0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0 0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0 0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Programs that read this format should be as lenient as possible, accepting anything that looks remotely like a graymap. COMPATIBILITY
Before April 2000, a raw format PGM file could not have a maxval greater than 255. Hence, it could not have more than one byte per sample. Old programs may depend on this. Before July 2000, there could be at most one image in a PGM file. As a result, most tools to process PGM files ignore (and don't read) any data after the first image. SEE ALSO
fitstopgm(1), fstopgm(1), hipstopgm(1), lispmtopgm(1), psidtopgm(1), rawtopgm(1), pgmbentley(1), pgmcrater(1), pgmedge(1), pgmenhance(1), pgmhist(1), pgmnorm(1), pgmoil(1), pgmramp(1), pgmtexture(1), pgmtofits(1), pgmtofs(1), pgmtolispm(1), pgmtopbm(1), pnm(5), pbm(5), ppm(5) AUTHOR
Copyright (C) 1989, 1991 by Jef Poskanzer. 12 November 1991 pgm(5)
All times are GMT -4. The time now is 09:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy