Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-08-2012
Registered User
 
Join Date: Jul 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Question [Solved] if condition in ksh

in my code if condition is not working.
i am using array in the if condition

the code:

Code:
set -A rt 0 1 7 13 21 

echo "Please enter a choice"
read choice;
for i in 0 1 2 3 4
 do
    if ['$choice' = ${rt[$i]}]
    then 
        echo "something"
    fi
 done


Last edited by Scrutinizer; 07-08-2012 at 03:40 AM.. Reason: code tags
Sponsored Links
    #2  
Old 07-08-2012
Registered User
 
Join Date: Jul 2012
Location: Chennai
Posts: 453
Thanks: 34
Thanked 57 Times in 55 Posts
why dont u look at this?

Hope this helps
Sponsored Links
    #3  
Old 07-08-2012
elixir_sinari's Avatar
Gotham Knight
 
Join Date: Mar 2012
Location: India
Posts: 1,370
Thanks: 87
Thanked 476 Times in 456 Posts

Code:
if [ "$choice" = "${rt[$i]}" ]
then 
echo "something"
fi

The single quotes wouldn't allow variable evaluation by the shell. Also, if you are doing string comparison, always try to enclose the operands in double-quotes.
    #4  
Old 07-08-2012
Registered User
 
Join Date: Jul 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Still the 'if condition' is not working
Sponsored Links
    #5  
Old 07-08-2012
Scrutinizer's Avatar
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,341
Thanks: 144
Thanked 1,754 Times in 1,591 Posts
Try:

Code:
rt=(0 1 7 13 21)

Sponsored Links
    #6  
Old 07-08-2012
Registered User
 
Join Date: Jul 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you guys...
PiKK45 ... the link helped...
It is working now...
Sponsored Links
    #7  
Old 07-08-2012
Registered User
 
Join Date: Jul 2012
Location: Chennai
Posts: 453
Thanks: 34
Thanked 57 Times in 55 Posts
Great!!
Sponsored Links
Closed Thread

Tags
if condtion ksh

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[SOLVED] Sorting file and get everything on same line on condition brianjb Shell Programming and Scripting 0 06-05-2012 08:08 PM
[Solved] Delete files with condition awadeid UNIX for Dummies Questions & Answers 5 05-31-2012 11:56 AM
redirect stdout echo command in condition A run in condition B jao_madn Shell Programming and Scripting 3 11-02-2011 09:01 PM
Difference between [condition] and [[condition]] and ((condition)) when used with if condition soumyabubun HP-UX 2 05-06-2011 01:03 PM
[solved] merging two files and writing to another file- solved mlpathir Shell Programming and Scripting 1 10-07-2010 06:41 PM



All times are GMT -4. The time now is 07:01 PM.