LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 10-31-2004, 05:33 PM   #1
bendeco13
Member
 
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232

Rep: Reputation: 30
Question For Statement


Does any one know whats why this won't work:
Code:
for COLOR in x1 y1 x2 y2 x3 y3
do
   if [ $COLOR -ge 10 ];
   then
      if [ $COLOR == 10 ];
      then
         $COLOR=A   
      elif [ $COLOR == 11 ];
      then
         $COLOR=B
      elif [ $COLOR == 12 ];
      then
         $COLOR=C
      elif [ $COLOR == 13 ];
      then
         $COLOR=D
      elif [ $COLOR == 14 ];
      then
         $COLOR=E   
      elif [ $COLOR == 15 ];
      then
         $COLOR=F
      fi
   fi
done
Thanks in advance!!
 
Old 10-31-2004, 05:44 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
How do you expect the string x1 to
match against the integer 10?



Cheers,
Tink
 
Old 10-31-2004, 05:57 PM   #3
bendeco13
Member
 
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232

Original Poster
Rep: Reputation: 30
Awwwww.....
x1 was previously assigned a number, but it is supposed to call on the value that was previously assigned to x1, y1, x2 ...etc...etc...
this code will give a better explanation of what I'm trying to do...
Code:
if [ $x1 -ge 10 ];
then
   if [ $x1 == 10 ];
   then
      x1=A   
   elif [ $x1 == 11 ];
   then
      x1=B
   elif [ $x1 == 12 ];
   then
      x1=C
   elif [ $x1 == 13 ];
   then
      x1=D
   elif [ $x1 == 14 ];
   then
      x1=E
   elif [ $x1 == 15 ];
   then
      x1=F
   fi
fi
so....
if x1 was previously defined as:
x1=11
then x1 would obtain the value of B

I'm trying to make this into a for loop so that it will do it for all of the different parts (y1, x2, y2, ...etc...etc).
This will greatly shorten the length of the code...

This clearly doesn't work:
Code:
for PART in x1 y1 x2 y2 x3 y3
do
   if [ $$PART -ge 10 ];
   then
      .....
   fi
done
I know there's a different way to do this?

Last edited by bendeco13; 10-31-2004 at 06:00 PM.
 
Old 10-31-2004, 06:08 PM   #4
bendeco13
Member
 
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232

Original Poster
Rep: Reputation: 30
Is there a way to use an aliases to assign the value to the pointer?
like in the C language...
you can use *variable to point to the location of variable
 
Old 10-31-2004, 06:11 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Why not just:

Code:
for PART in $x1 $y1 $x2 $y2 $x3 $y3
do
   if [ $PART -ge 10 ];
   then
      .....
   fi
done

Cheers,
Tink
 
Old 10-31-2004, 06:12 PM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
Code:
# this=that
# the_other=this
# echo $the_other
this
# echo $((the_other))
that
that's the bit you're stuck on right?
 
Old 10-31-2004, 06:31 PM   #7
bendeco13
Member
 
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232

Original Poster
Rep: Reputation: 30
THANKS ALOT.....
That did part of it, but say I was doing this part:
Code:
for PART in x1 y1 x2 y2 x3 y3
do
   $PART=A
done
This should assign A to x1, y1, x2, y2, x3, and y3....but it don't
How could I do this?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
net use statement mnauta Linux - Networking 1 08-19-2005 02:21 PM
the FOR statement (C) sk84blood813 Programming 3 12-09-2004 09:25 AM
If Statement junjem0702 Programming 4 08-23-2004 10:49 AM
switch statement linuxanswer Programming 2 11-30-2003 12:25 AM
mysql statement... johnyy Linux - Software 1 11-02-2003 04:30 AM


All times are GMT -5. The time now is 04:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration