Sponsored Content
Top Forums Shell Programming and Scripting Comparison of two variables with IF loop Post 302758967 by Scott on Monday 21st of January 2013 06:09:37 AM
Old 01-21-2013
Your if statement has one opening [ and two closing ]]. You also need a space after [ and before ].

There's also an unnecessary use of echo and backticks:
Code:
TODAY=$(echo `date +"%b%d"`)

Could be:
Code:
TODAY=$(date +"%b%d")

This User Gave Thanks to Scott For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with if loop (string comparison)

Hi Can someone please tell me what is wrong with this (ksh).. if + ]] then echo ${COMP_TEMP} fi What i need here is, say if the variable is a 1 or 2 digit number, then execute the if loop. Basically the variable can either be 1-30 or some other character sequence say '?', '&&'... (4 Replies)
Discussion started by: psynaps3
4 Replies

2. Shell Programming and Scripting

Is there a better way I could have run this loop. (For loop with two variables)

Sorry for such a dreadful title, but I'm not sure how to be more descriptive. I'm hoping some of the more gurutastic out there can take a look at a solution I came up with to a problem, and advice if there are better ways to have gone about it. To make a long story short around 20K pieces of... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

3. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

4. UNIX for Advanced & Expert Users

Comparison and For Loop Taking Too Long

I'd like to 1. Check and compare the 10,000 pnt files contains single record from the /$ROOTDIR/scp/inbox/string1 directory against 39 bad pnt files from the /$ROOTDIR/output/tma/pnt/bad/string1 directory based on the fam_id column value start at position 38 to 47 from the record below. Here is... (1 Reply)
Discussion started by: hanie123
1 Replies

5. Shell Programming and Scripting

String comparison not working inside while loop

Hi, In the code included below, the string comparision is not working fine. Please help while (( find_out >= i )) do file=`head -$i f.out|tail -1` dir=`dirname $file` cd $dir Status="" if ; then Status=`cvs -Q status... (3 Replies)
Discussion started by: sudvishw
3 Replies

6. Shell Programming and Scripting

string comparison not working inside while loop

The string comparison highlighted below is not working fine. Please help: while read line do # Get File name by deleting everything that preceedes and follows Filename as printed in cvs status' output f_name=`echo $line | sed -e 's/^File://' -e 's/ *Status:.*//' | awk '{print $NF}'` ... (4 Replies)
Discussion started by: sudvishw
4 Replies

7. Shell Programming and Scripting

for loop with 2 variables

i am having a file contants as below my requirement is for file in `awk -F "," '{print $8,$9}'` <temp.txt echo "$file" echo "$file">test.txt a=`awk -F "," '{print $1}' `<test.txt b=`awk -F "," '{print $2}' `<test.txt but script reads , i want both the vales for further... (5 Replies)
Discussion started by: sagar_1986
5 Replies

8. Shell Programming and Scripting

While loop for comparison

hi all, i have two files: test1 contains : one two three four five (on separate lines) test2 contains: one ten nine (on separate lines) I want to compare two files, test1 against test2. if any word from test1 does not match test2 display it. can someone help me with a while loop on this. ... (4 Replies)
Discussion started by: sbk785
4 Replies

9. Shell Programming and Scripting

awk - 2 files comparison without for loop - multi-line issue

Greetings Experts, I need to handle the views created over monthly retention tables for which every new table in YYYYMMDD format, there is equivalent view created and the older table which might be dropped, the view over it has to be re-created over a dummy table so that it doesn't fail.... (2 Replies)
Discussion started by: chill3chee
2 Replies

10. Shell Programming and Scripting

Help with variables in loop

Hello, please assist: users="test1 test2" keytest1="abcd" keytest2="dbcd" for i in $users do echo "$key${i}" > fileout done So, my objective is to take the current user (ie test1) in loop and echo its associated keyname (ie keytest1) variable to a file. The echo... (2 Replies)
Discussion started by: motdman
2 Replies
DATETIME.ADD(3) 							 1							   DATETIME.ADD(3)

DateTime::add - Adds an amount of days, months, years, hours, minutes and seconds to a DateTime object

       Object oriented style

SYNOPSIS
public DateTime DateTime::add (DateInterval $interval) DESCRIPTION
Procedural style DateTime date_add (DateTime $object, DateInterval $interval) Adds the specified DateInterval object to the specified DateTime object. PARAMETERS
o $object -Procedural style only: A DateTime object returned by date_create(3). The function modifies this object. o $interval - A DateInterval object RETURN VALUES
Returns the DateTime object for method chaining or FALSE on failure. EXAMPLES
Example #1 DateTime.add(3) example Object oriented style <?php $date = new DateTime('2000-01-01'); $date->add(new DateInterval('P10D')); echo $date->format('Y-m-d') . " "; ?> Procedural style <?php $date = date_create('2000-01-01'); date_add($date, date_interval_create_from_date_string('10 days')); echo date_format($date, 'Y-m-d'); ?> The above examples will output: 2000-01-11 Example #2 Further DateTime.add(3) examples <?php $date = new DateTime('2000-01-01'); $date->add(new DateInterval('PT10H30S')); echo $date->format('Y-m-d H:i:s') . " "; $date = new DateTime('2000-01-01'); $date->add(new DateInterval('P7Y5M4DT4H3M2S')); echo $date->format('Y-m-d H:i:s') . " "; ?> The above example will output: 2000-01-01 10:00:30 2007-06-05 04:03:02 Example #3 Beware when adding months <?php $date = new DateTime('2000-12-31'); $interval = new DateInterval('P1M'); $date->add($interval); echo $date->format('Y-m-d') . " "; $date->add($interval); echo $date->format('Y-m-d') . " "; ?> The above example will output: 2001-01-31 2001-03-03 NOTES
DateTime.modify(3) is an alternative when using PHP 5.2. SEE ALSO
DateTime.sub(3), DateTime.diff(3), DateTime.modify(3). PHP Documentation Group DATETIME.ADD(3)
All times are GMT -4. The time now is 02:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy