Assigning numeric values to variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Assigning numeric values to variable
# 1  
Old 12-06-2012
Assigning numeric values to variable

I have a code like this

Code:
v_num=9
 comp_num=39
 if [$v_num -gt $comp_num] 
 then
 echo "pass"
 fi
 echo "end"

I am getting an error

ksh: [9: not found
end

When I change the code to

Code:
v_num=99
 comp_num=39
 if [$v_num -gt $comp_num]
 then
 echo "pass"
 fi
 echo "end"

I am getting error
ksh: [99: not found
end

I guess the constants are not getting recognized.
Please help
# 2  
Old 12-06-2012
you should give the space in the condition..
Code:
if [ $v_num -gt $comp_num ]

This User Gave Thanks to bmk For This Post:
# 3  
Old 12-06-2012
Please use spaces between square brackets.

Code:
if [ $v_num -gt $comp_num ]


Last edited by pamu; 12-06-2012 at 02:07 AM.. Reason: already provided by BMK :)
This User Gave Thanks to pamu For This Post:
# 4  
Old 12-06-2012
spacing around your tests (the square brackets need to be separate tokens
Code:
a=9
b=10
if [ a -gt b ]
then
  echo what now
else
  echo that makes sense
fi

This User Gave Thanks to Skrynesaver For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Assigning a value to a variable name then running a loop on these values

Hi, I was wondering if anyone could assist me for (what is probably) a very straightforward answer. I have input files containing something like File 1 Apples Apples Apples Apples File 2 Bananas Bananas Bananas Bananas (4 Replies)
Discussion started by: hubleo
4 Replies

2. Shell Programming and Scripting

help with assigning multiple values to a variable

I have a situation where my variable needs to pick up any of the 4 values from the environment it is in for e.g i am on server named a server=a (script running on this server) ftp servers= b c d e ----- the parameter passed should be any of these values in these 4 values, if not throw an... (4 Replies)
Discussion started by: dsravan
4 Replies

3. Shell Programming and Scripting

Assigning a set of values to a variable

I wnat to assign a set of values to a variable and use it in if condition. for example: i=$1 d=1 2 3 4 5 6 if then echo "Fine" else echo "Check" fi i will either of the value in d, i.e. i can be 1 or 2 or any value in d, How this can be done? Thanks in advance (2 Replies)
Discussion started by: sol_nov
2 Replies

4. Shell Programming and Scripting

ksh help assigning specific values to variable in script

Hi - Help needed. I have an input file that looks something like this, but with a lot more entries: A Customer1 B 4500 C 8000 A Customer2 B 6422 C 8922 I need to be able to print details for each customer on one line per customer. ie. if I could print these to a file and then cat... (3 Replies)
Discussion started by: frustrated1
3 Replies

5. Shell Programming and Scripting

Assigning multiple values to a variable

Hi Guru`s, I have to write a prog. which will traverse through diff. directories and then extract some data from files. I have written it and its working fine. But I have tested it in 1 folder. There are many folders and I need to loop through each of them. I am not sure abt the... (4 Replies)
Discussion started by: unx100
4 Replies

6. Programming

numeric values ending in 'U'

I am getting back on the C++ programming after many years away. I recently received an SDK that has code like this where numeric values end in 'U'. What does this mean? if ((ptr % 16U) == 0U) return buffer; (3 Replies)
Discussion started by: sneakyimp
3 Replies

7. Shell Programming and Scripting

Remove non numeric values from a variable

Hello all, I am working on a basic script but need a little help. Issue: I am running a SQL Query using sqlplus and a shell script. I have the output of the statement stored as variable $A. $A is set to "other text here 45678754 other text here". I need to strip all text except that numeric... (13 Replies)
Discussion started by: ownedthawte
13 Replies

8. UNIX for Dummies Questions & Answers

assigning (numeric) command output to var tcsh

Hello, I'm trying to assign a numeric value that is returned from one of my programs to a variable in tcsh. I want to do: @ r10 = './my_prog file 35' where ./my_prog file 35 returns a decimal value, but this doesn't work. How do I achieve the desired result? Janet (4 Replies)
Discussion started by: psran
4 Replies

9. Shell Programming and Scripting

problem assigning values to variable

Date of Request: 20080514 10:37 Submitted By: JPCHIANG i want to get the value "JPCHIANG" only in read a file, however, when i do this: name=`"$line"|cut -d " " -f8` it display all the line and append 'not found' at the end of the statement the $line is actually a variable in a... (2 Replies)
Discussion started by: finalight
2 Replies

10. UNIX for Dummies Questions & Answers

assigning values to a variable

i try to get the year and month values using the below shell script when i enter the script like this #!/usr/bin/ksh dd=`DATE +%Y%M` echo $dd it is showing the error as shown below abc.ksh: DATE: not found any suggestions please (3 Replies)
Discussion started by: trichyselva
3 Replies
Login or Register to Ask a Question