The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
bash and ksh: variable lost in loop in bash? estienne Shell Programming and Scripting 2 08-25-2008 02:09 PM
What can make Cronjobs stop working?? Nintendo UNIX for Dummies Questions & Answers 0 06-04-2008 02:40 PM
Increment date in 'for' loop? SunnyK Shell Programming and Scripting 4 10-30-2007 06:12 AM
korn shell to bash - statement not working brdholman UNIX for Dummies Questions & Answers 5 10-15-2007 09:49 AM
how to stop execution in for loop useless79 High Level Programming 1 09-06-2007 10:54 PM

Closed Thread
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
  #1 (permalink)  
Old 11-07-2008
alex_5161 alex_5161 is offline
Registered User
  
 

Join Date: Jan 2007
Location: Detroit
Posts: 124
Anyone know?: How the 'for'-loop could stop working in interactive bash shell?!

It is happening with my sessions already second time: a 'for'-loop for some reason stop to work as expected.
That means or it is looping without exitting, or it is not loop even once.

Here example of my try when it is not processing even one loop.
You can see, I start new subshell and 'for' works fine, but returning back, the 'for' doesn't work again"
Code:
> for ((i=1;i<3;i++));do echo $i; done;
> echo mm
mm
> for ((i=1;i<3;i++));do echo $i; done;
> bash
executing file .bashrc - starting the bash shell--

----> Start of the .myset file  <---

  ----  It is SUN0 box with TEST and MODEL offices  ----

----> End   of the .myset file  <---
>
>
> for ((i=1;i<3;i++));do echo $i; done;
1
2
> 
> exit
exit
> for ((i=1;i<3;i++));do echo $i; done;
> echo boooo
boooo
>
>
Does anybody know what could be a reason?
I do not think it is related to connection soft (I use PuTTY.)

Appreciate any help or hint
  #2 (permalink)  
Old 11-07-2008
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,116
Code:
bash-3.00$ for ((i=1;i<3;i++));do echo $i; done;
1
2
bash-3.00$ for ((i=1;i<3;i++));do echo $i; done;
1
2
bash-3.00$ for ((i=1;i<3;i++));do echo $i; done;
1
2
bash-3.00$ for ((i=1;i<3;i++));do echo $i; done;
1
2
bash-3.00$ for ((i=1;i<3;i++));do echo $i; done;
1
2
bash-3.00$ echo booo
booo
bash-3.00$ for ((i=1;i<3;i++));do echo $i; done;
1
2
bash-3.00$
bash-3.00$ for ((i=1;i<3;i++));do echo $i; done;
1
2
bash-3.00$
I can't reproduce your symptom. And I was using putty.
  #3 (permalink)  
Old 11-07-2008
alex_5161 alex_5161 is offline
Registered User
  
 

Join Date: Jan 2007
Location: Detroit
Posts: 124
It is correct, you can't reproduce it!
And I too, can not reproduce it!
I have this situation second time.
First time I have spend couple hours trying to realize what is wrong with my script, untill did not gess to try it in another session, where everything works fine.
Now some how it is happened again. Hopefully some time I could learn from past; so I have realized it shortly.
Now the session is oppened and I could make some test, if anybody would advice to try anything

As I have said, I have no idea how and why that is happening and that is my question, if anybody have any clue about that?!?!
  #4 (permalink)  
Old 11-07-2008
Lakris Lakris is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 246
Hello,
this may be a long shot, but maybe You have an alias or something that is active in Your first shell (a login shell perhaps, that read .bash_login?) and the next shell is not a login shell and hence has some other definitions that overrule the first ones?
save output from alias and set from each shell and compare them. It maybe a lot of text but You said You wanted to understand...
use sort and -u on each file to narrow down size and then diff.

/Lakris
  #5 (permalink)  
Old 11-07-2008
alex_5161 alex_5161 is offline
Registered User
  
 

Join Date: Jan 2007
Location: Detroit
Posts: 124
Thanks Lakris.

Relation to login is not a reason, because a new connection has no problem originally. When that happened I di not know.

I have compared the aliases:
Code:
> alias >bad_alias
> !for
for ((i=1;i<3;i++));do ec $i; done;
>
>
In another session:
Code:
> for ((i=1;i<3;i++));do ec $i; done;
1
2
> alias>good_alias
>
>
> diff bad_alias good_alias
>                                    # so files are the same
>
Also I have saved result of 'typeset' and 'env'
Later will review (some function I could add, change during mork.)

But on first glance there is no real difference.
  #6 (permalink)  
Old 11-08-2008
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 708
Hi.

It might be useful to see how the shell is interpreting everything. Using set -x will show you the commands. This is from a vanilla bash called as sh:
Code:
$ set -x
+ set -x
sh-2.05b$ for ((i=1;i<3;i++));do echo $i; done;
+ (( i=1 ))
+ (( i<3 ))
+ echo 1
1
+ (( i++ ))
+ (( i<3 ))
+ echo 2
2
+ (( i++ ))
+ (( i<3 ))
cheers, drl
  #7 (permalink)  
Old 11-10-2008
alex_5161 alex_5161 is offline
Registered User
  
 

Join Date: Jan 2007
Location: Detroit
Posts: 124
Thank you, drl, set -x realy interesting thing.

It seems the shell some how do not processing assighment in the (( )).
Also in 'let' and in 'expr' ('ec' is an alianse for echo)
Code:
>ec $i; expr i++; ec $i
+ /usr/bin/echo 2
2
+ expr i++
i++
+ /usr/bin/echo 2
2
>ec $i; expr i++; expr i=1; ec $i
+ /usr/bin/echo 2
2
+ expr i++
i++
+ expr i=1
i=1
+ /usr/bin/echo 2
2
>ec $i; expr i++; let i=1; ec $i
+ /usr/bin/echo 2
2
+ expr i++
i++
+ let i=1
+ /usr/bin/echo 2
2
>ec $i; expr i++; i=1; ec $i
+ /usr/bin/echo 2
2
+ expr i++
i++
+ i=1
+ /usr/bin/echo 1
1
>ec $i; expr i++; i=$((i++)); ec $i
+ /usr/bin/echo 1
1
+ expr i++
i++
+ i=1
+ /usr/bin/echo 1
1
>
Closed Thread

Bookmarks

Tags
linux commands, unix commands

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 02:38 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