|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Comparison of two variables with IF loop
Hello, My script is like : Code:
#!/bin/sh -x
TODAY=$(echo `date +"%b%d"`)
FILE_DATE=$(ls -l test.sh | awk '{print $6$7}')
echo "file date=$FILE_DATE"
echo "date=$TODAY"
if ["$TODAY" == "$FILE_DATE"]];then
echo "file is correct"
else
echo "file is incorrect"
fiand The Output is : Code:
$ ./test.sh
+ + date +%b%d
+ echo Jan21
TODAY=Jan21
+ + ls -l test.sh
+ awk {print $6$7}
FILE_DATE=Jan21
+ echo file date=Jan21
file date=Jan21
+ echo date=Jan21
date=Jan21
+ [Jan21 == Jan21]]
./test.sh[6]: [Jan21: not found
+ echo file is incorrect
file is incorrectPlease let me know where i am doing wrong. Regards, saurau |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
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") |
| The Following User Says Thank You to Scott For This Useful Post: | ||
saurau (01-21-2013) | ||
| Sponsored Links | ||
|
|
#4
|
|||
|
|||
|
Quote:
![]() |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| string comparison not working inside while loop | sudvishw | Shell Programming and Scripting | 4 | 12-31-2010 12:02 PM |
| String comparison not working inside while loop | sudvishw | Shell Programming and Scripting | 3 | 12-30-2010 06:49 AM |
| Comparison and For Loop Taking Too Long | hanie123 | UNIX for Advanced & Expert Users | 1 | 07-10-2009 07:50 AM |
| Using variables created sequentially in a loop while still inside of the loop [bash] | DeCoTwc | Shell Programming and Scripting | 2 | 06-23-2009 04:59 PM |
| Help with if loop (string comparison) | psynaps3 | Shell Programming and Scripting | 4 | 07-07-2006 02:36 AM |
|
|