compare two variable value in unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting compare two variable value in unix
# 1  
Old 08-08-2008
compare two variable value in unix

dear all

i had two variable in my script.
var1 and var2

var1= 10 ( it will part of date op ) Fri Aug 8 10:05:09 IST 2008
var2=9 ( it will op of ls -ltr and time part of it.)

now i want to compare of them and want to do some task if both are are not same.

kindly let me know possible way...

rgd
jaydeep
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare pattern in variable

How to check if pattern is matching in variable or not. I want to check file name in variable with the pattern. Eg: file_name="AB1000.csv" Check for below patterns pattern1 = AB??? pattern2 = abc??* if file_name == <patten1> then ... elif file_name == <pattern2> ---... (4 Replies)
Discussion started by: vegasluxor
4 Replies

2. Shell Programming and Scripting

Compare the two variable with if condition

Please help me with this: I need to compare two values in if condition in shell script but its goes always to else condition: TIME_CHECK=PM TIME-CLOCK=PM if ; then echo "You have access!" else echo "ACCESS DENIED!" fi (5 Replies)
Discussion started by: aroragaurav.84
5 Replies

3. UNIX for Dummies Questions & Answers

awk unable to compare the shell variable

Hi Could anyone please help with Awk. The below code prints the PID of the matching process with condition with $8 and $9 ps -ef |awk '($8~/proc/) && ($9~/rPROC2/) {print $2}' Now i want to change the Constant PROC2 from Shell variable PROC2 is already declared in shell variable SRVNAME... (9 Replies)
Discussion started by: rakeshkumar
9 Replies

4. Red Hat

Compare Empty Variable

Hello All, I am running the below code in my script. I want if jk is empty nothing should be appened to the file total_usage. but apparently its not happening.Kindy let me know how to do it. ################################### jk=`ps auxf |grep -w $inputline|tr -s " "|cut -d... (0 Replies)
Discussion started by: ajaincv
0 Replies

5. Shell Programming and Scripting

KSH: Compare variable to $1 in an input file

Hello, I am working with KSH on AIX and I have 2 files generated from different sources... as seen below: FILE1 FILE2 AAA AAA@ABS0001C BBB BBB@ABS0003D CCC CCC@ABS0023A DDD DDD@ABC0145D EEE EEE@ABS0090A FFF FFF@ABS0002A GGG GGG@ABC0150D HHH FILE1 is main main data source,... (4 Replies)
Discussion started by: right_coaster
4 Replies

6. Shell Programming and Scripting

AWK help: how to compare array elements against a variable

i have an array call ignore. it is set up ignore=34th56 ignore=re45ty ignore=rt45yu . . ignore=rthg34 n is a variable. I have another variable that i read from a different file. It is $2 and it is working the way i expect. array ignore read and print correct values. in the below if... (2 Replies)
Discussion started by: usustarr
2 Replies

7. UNIX for Dummies Questions & Answers

unix compare two variable

how can i unix compare two variable?? var1 = 6499 7328 6351 7583 7573 var2 = 6499 7328 6351 7583 7573 i did: diff $var1 $var2 and i got the output: diff: extra operand `6351' diff: Try `diff --help' for more information. whats wrong?? (5 Replies)
Discussion started by: nirnir26
5 Replies

8. Shell Programming and Scripting

compare a variable against array elements

hi everyone - i have a bash script that does, in broad terms, the following: given a file containing a list of email accounts, for every account, do , then move on to the next account. pretty simple, and all that stuff works fine. thing is, there's a very good change that any account... (2 Replies)
Discussion started by: fearboy
2 Replies

9. Shell Programming and Scripting

compare variable against regular expression?

is it possible? if so, how? i want to check a variable whether is it a number or letter in an if-else statement (6 Replies)
Discussion started by: finalight
6 Replies

10. UNIX for Dummies Questions & Answers

Compare the content of a variable with a string

Hello all: I'm new in Unix and here and I'am spanish so my english isn't so good to explain my doubt. Here it is. Very urgent: I need to compare the value of a variable with a string. Example is this. Imagine that the variable x1 contains the path and a file text and I need to compare... (2 Replies)
Discussion started by: robdai
2 Replies
Login or Register to Ask a Question
Template::Stash(3)					User Contributed Perl Documentation					Template::Stash(3)

NAME
Template::Stash - Magical storage for template variables SYNOPSIS
use Template::Stash; my $stash = Template::Stash->new(\%vars); # get variable values $value = $stash->get($variable); $value = $stash->get(@compound); # set variable value $stash->set($variable, $value); $stash->set(@compound, $value); # default variable value $stash->set($variable, $value, 1); $stash->set(@compound, $value, 1); # set variable values en masse $stash->update(\%new_vars) # methods for (de-)localising variables $stash = $stash->clone(\%new_vars); $stash = $stash->declone(); DESCRIPTION
The "Template::Stash" module defines an object class which is used to store variable values for the runtime use of the template processor. Variable values are stored internally in a hash reference (which itself is blessed to create the object) and are accessible via the get() and set() methods. Variables may reference hash arrays, lists, subroutines and objects as well as simple values. The stash automatically performs the right magic when dealing with variables, calling code or object methods, indexing into lists, hashes, etc. The stash has clone() and declone() methods which are used by the template processor to make temporary copies of the stash for localising changes made to variables. PUBLIC METHODS
new(\%params) The "new()" constructor method creates and returns a reference to a new "Template::Stash" object. my $stash = Template::Stash->new(); A hash reference may be passed to provide variables and values which should be used to initialise the stash. my $stash = Template::Stash->new({ var1 => 'value1', var2 => 'value2' }); get($variable) The "get()" method retrieves the variable named by the first parameter. $value = $stash->get('var1'); Dotted compound variables can be retrieved by specifying the variable elements by reference to a list. Each node in the variable occupies two entries in the list. The first gives the name of the variable element, the second is a reference to a list of arguments for that element, or 0 if none. [% foo.bar(10).baz(20) %] $stash->get([ 'foo', 0, 'bar', [ 10 ], 'baz', [ 20 ] ]); set($variable, $value, $default) The "set()" method sets the variable name in the first parameter to the value specified in the second. $stash->set('var1', 'value1'); If the third parameter evaluates to a true value, the variable is set only if it did not have a true value before. $stash->set('var2', 'default_value', 1); Dotted compound variables may be specified as per get() above. [% foo.bar = 30 %] $stash->set([ 'foo', 0, 'bar', 0 ], 30); The magical variable '"IMPORT"' can be specified whose corresponding value should be a hash reference. The contents of the hash array are copied (i.e. imported) into the current namespace. # foo.bar = baz, foo.wiz = waz $stash->set('foo', { 'bar' => 'baz', 'wiz' => 'waz' }); # import 'foo' into main namespace: bar = baz, wiz = waz $stash->set('IMPORT', $stash->get('foo')); clone(\%params) The "clone()" method creates and returns a new "Template::Stash" object which represents a localised copy of the parent stash. Variables can be freely updated in the cloned stash and when declone() is called, the original stash is returned with all its members intact and in the same state as they were before "clone()" was called. For convenience, a hash of parameters may be passed into "clone()" which is used to update any simple variable (i.e. those that don't contain any namespace elements like "foo" and "bar" but not "foo.bar") variables while cloning the stash. For adding and updating complex variables, the set() method should be used after calling "clone()." This will correctly resolve and/or create any necessary namespace hashes. A cloned stash maintains a reference to the stash that it was copied from in its "_PARENT" member. declone() The "declone()" method returns the "_PARENT" reference and can be used to restore the state of a stash as described above. AUTHOR
Andy Wardley <abw@wardley.org> <http://wardley.org/> COPYRIGHT
Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Template, Template::Context perl v5.12.1 2009-05-20 Template::Stash(3)