Operating System - HP-UX
1753856 Members
7307 Online
108809 Solutions
New Discussion юеВ

Re: loop control inside function

 
Stoyan Stoyanov_1
New Member

loop control inside function

Hi All,
I need some clarification (and maybe more information) about the attached example script, which is working fine (as it expected) under bash, but not under ksh88/93. In ksh the "break" and "continue" does not do their job if they are passed to the loop from a function. For the "exit" it is OK.
Please advice.

3 REPLIES 3
Steven E. Protter
Exalted Contributor

Re: loop control inside function

Shalom,

Reading:

http://my.safaribooksonline.com/0596003307/upt3-CHP-31-SECT-6

loop control works the same way outside as inside a function.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: loop control inside function

Hi:

A 'break' or 'continue' exits from a 'for', 'select', 'until', or 'while' loop, not from a function in the POSIX (or 'ksh') shells.

An 'exit' causes termination of the whole script. A 'return' exits from a _function_.

Yes, the behavior of the Bash shell is different.

If you are running on HP-UX, using a Bash shell is fine _AS_LONG_AS_ you _NEVER_ make it the default shell for root.

The POSIX shell in '/sbin/sh' doesn't use shared libraries which aren't available in single user mode. Hence it MUST be the only shell used during startup. If you change root's default shell to anything else, you will render your system un-startable!

Regards!

...JRF...
Stoyan Stoyanov_1
New Member

Re: loop control inside function

Thank you both,
for fast and accurate response.
James I've never wanted to change the default root's shell, even I didn't want to install the bash, because of that I found the way to simulate the behavior of bash under ksh in that current situation; it's just using one simple variable.
And thank you again you two.