Results 1 to 4 of 4
I need to compare two values in same arrar and I don't want to hardcode it, need the logic (still trying to create some logic)..
Following is hardcoded example need ...
- 02-04-2008 #1Linux Newbie
- Join Date
- Jan 2008
- Posts
- 114
How to compare values in Same Array instead of if ($test[0] != 1 && $test[1] != 1){
I need to compare two values in same arrar and I don't want to hardcode it, need the logic (still trying to create some logic)..
Following is hardcoded example need to change it:-
Some thing like this, not hardcodedCode:@test; if ($test[0] != 1 && $test[1] != 1){ print "Test Passed\n"; }else { Print "Test Failed\n"; } Want to in this way foreach $t1 (@test){ if (
Please suggest me
ThanksLast edited by devils casper; 02-05-2008 at 08:04 AM. Reason: Added [code].....[/code] tags.
- 02-05-2008 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
It should be something like:
RegardsCode:for i in "${test[@]}" do echo "$i" done
- 02-05-2008 #3Linux Newbie
- Join Date
- Jan 2008
- Posts
- 114
And what about my if condition???
This will only print the values of array
- 02-05-2008 #4Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
The previous example shows how to loop through the elements of an array.
In your situation you can use a temporary variable for the first element.
It should be something like:
Have a read of some useful links for bash scripting:Code:for i in "${test[@]}" do if [ flag == 0 ]; then temp=$i flag=1 else flag=0 if [ $1 != 1 ] && [ $temp != 1 ]; then 'Do your stuff here fi fi done
BASH Programming - Introduction HOW-TO
http://tldp.org/LDP/abs/html/
Regards


Reply With Quote