The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem with variable expension using for loop. ejdv Shell Programming and Scripting 2 06-16-2008 11:15 AM
while read loop w/ a nested if statement - doesn't treat each entry individually littlefrog Shell Programming and Scripting 7 12-11-2007 09:49 PM
For loop statement - catch error lumdev Shell Programming and Scripting 4 09-20-2007 08:50 AM
if statement in a while loop bobo UNIX for Dummies Questions & Answers 2 11-07-2006 12:38 PM
if statement in for loop of a string Sniper Pixie UNIX for Dummies Questions & Answers 7 03-02-2006 07:28 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 06-17-2008
ejdv ejdv is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 46
Question Variable problem in for loop with if statement

Hi,

Again a little problem.
Do not understand good why an empty string is not detected.
Here is the program:

#!/bin/ksh

APR=`date | grep Apr | awk '{print $2$3}'`
MAY=`date | grep May | awk '{print $2$3}'`
JUN=`date | grep Jun | awk '{print $2$3}'`

echo "Variable Apr has value: $APR"
echo "Variable May has value: $MAY"
echo "Variable Jun has value: $JUN"
echo

for ITEM in $APR $MAY $JUN
do
if [[ "${ITEM}" = "" ]]
then
echo "The checked item has no value."
else
echo "The checked item has value ${ITEM}"
fi
done

Output:

Variable Apr has value:
Variable May has value:
Variable Jun has value: Jun17

The checked item has value Jun17

I expected it a little different.
Maybe this is an issue:

# echo $MAY | od -c
0000000 \n
0000001

Thanks in advance,

ejdv
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:40 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0