Sponsored Content
Top Forums Shell Programming and Scripting variables usage without dereferencing Post 302164594 by ag79 on Tuesday 5th of February 2008 10:57:02 AM
Old 02-05-2008
variables usage without dereferencing

Hi All,

I came across a bit of code that seems to work, even though I didn't expect it to (now that's wierd!)

#!/bin/sh
set -x
nn=15
if [ nn -eq 15 ]
then
echo "is true"
fi

The above code ends up comparing the string "nn" to number 15, but still evaluates to true. Here's the output when i run it :

+ nn=15
+ [ nn -eq 15 ]
+ echo is true
is true


while with [ "$nn" -eq 15 ], I get:

+ nn=15
+ [ 15 -eq 15 ]
+ echo is true
is true

which is what I expect.

By the way, if you assign nn=25 and run test nn -eq 15, it evaluates to false.

Any Ideas how the integer comparison is working without dereferencing the variable? Smilie

Last edited by ag79; 02-06-2008 at 11:36 AM..
 

10 More Discussions You Might Find Interesting

1. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

2. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

3. Shell Programming and Scripting

Dereferencing (?) in Perl

Hi, i want to print the mail exchange servers for a domain using the code below, the problem is that i just get the memory locations (?) of the elements in the output, instead of the mx servers. I really tried to find a solution, but i guess that i just don't get it (objects, OOP etc).. :) ... (2 Replies)
Discussion started by: mjoh
2 Replies

4. Programming

Dereferencing pointer to incomplete type

// Hello all, I am having this error "Dereferencing pointer to incomplete type " on these 2 lines: xpoint = my_point->x; ypoint = my_point->y; I am having no clue y this is happening. Any help would be greately appreciated!!!! #include<stdio.h> #include<string.h>... (2 Replies)
Discussion started by: mind@work
2 Replies

5. Shell Programming and Scripting

Dereferencing in PERL

Hi, This should be a simple one. All I am doing is adding an email address to my email. Example abc@xyz.com I understand that the @ means arrays in PERL. So, I coded the backtick (`) to dereference it. But now I get abc`@`xyz.com Your help is appreciated. Thanks Nurani (2 Replies)
Discussion started by: nurani
2 Replies

6. Programming

Dereferencing pointer to a shared memory struct

I have what should be a relatively simple program (fadec.c) that maps a struct from an included header file (fadec.h) to a shared memory region, but I’m struggling accessing members in the struct from the pointer returned by shmat. Ultimately, I want to access members in the shared memory structure... (2 Replies)
Discussion started by: arette
2 Replies

7. Programming

Compilation Error: dereferencing pointer to incomplete type

I am getting a dereferencing pointer to incomplete type error when i compile the following code on lines highlighted in red. Can anyone help me in identifying what is wrong in the code? #include<stdio.h> #include<stdlib.h> typedef struct{ int info; struct node* link ; } node; void... (3 Replies)
Discussion started by: sreeharshasn
3 Replies

8. Shell Programming and Scripting

perl: dereferencing a hash of hashes

Hi there, I am trying to dereference my hash of hashes but post dereferencing, it seems to lose its structure I am using Data::dumper to help me anaylise. This is the code im using to build the HoH, (data comes from a file). I have also performed a Dumper on the data structure before and after... (1 Reply)
Discussion started by: rethink
1 Replies

9. Shell Programming and Scripting

Dereferencing variable in loop

Hi , I have below code While running above code i am receiving error : bad substitution I need to use the variable s RC_1, RC_2 and their value outside of the loop. Can anybody help me on that (5 Replies)
Discussion started by: sonu_pal
5 Replies

10. Shell Programming and Scripting

Dereferencing variable inside egrep call

Hi guys I am trying to dereference a variable inside 'egrep -v ' command and getting a 'egrep: syntax error' : $ echo $exclude_list ts584d hf584db for i in `echo $exclude_list`; do egrep -v ${i} my_file done egrep: syntax error egrep: syntax error The syntax of the loop is correct.... (1 Reply)
Discussion started by: aoussenko
1 Replies
IS_INT(3)								 1								 IS_INT(3)

is_int - Find whether the type of a variable is integer

SYNOPSIS
bool is_int (mixed $var) DESCRIPTION
Finds whether the type of the given variable is integer. Note To test if a variable is a number or a numeric string (such as form input, which is always a string), you must use is_numeric(3). PARAMETERS
o $var - The variable being evaluated. RETURN VALUES
Returns TRUE if $var is an integer, FALSE otherwise. EXAMPLES
Example #1 is_int(3) example <?php $values = array(23, "23", 23.5, "23.5", null, true, false); foreach ($values as $value) { echo "is_int("; var_export($value); echo ") = "; var_dump(is_int($value)); } ?> The above example will output: is_int(23) = bool(true) is_int('23') = bool(false) is_int(23.5) = bool(false) is_int('23.5') = bool(false) is_int(NULL) = bool(false) is_int(true) = bool(false) is_int(false) = bool(false) SEE ALSO
is_bool(3), is_float(3), is_numeric(3), is_string(3), is_array(3), is_object(3). PHP Documentation Group IS_INT(3)
All times are GMT -4. The time now is 04:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy