Thread View: gnu.bash.bug
2 messages
2 total messages
Started by Salvador Pinto Abreu
Thu, 27 Aug 1992 14:36
odd `shift' behaviour with bash-1.12
Author: Salvador Pinto Abreu
Date: Thu, 27 Aug 1992 14:36
Date: Thu, 27 Aug 1992 14:36
33 lines
1398 bytes
1398 bytes
The scope of the `shift' command seems to be the innermost loop. For
example, the following code:
MAX_PARALLEL=...
MAX_PARALLEL_COUNT=$(echo -n $MAX_PARALLEL | wc -c)
function bug {
local PARALLEL
while [ -n "$1" ]; do
PARALLEL=$MAX_PARALLEL
echo 1>&2 bug: entering parallel loop.
while [ -n "$1" -a -n "$PARALLEL" ]; do
( echo bug: output of $1 & )
PARALLEL=${PARALLEL#.}
shift
done | cat
[ -z "$LOOP" ] && shift $MAX_PARALLEL_COUNT
done
}
bug 1 2 3 4 5 6 7 8 # runs fine
LOOP=on
bug 1 2 3 4 5 6 7 8 # loops
the second `shift' needs to be executed to shift the args to `bug',
even though they were already (supposed to have been) kicked out by
the `shift' in the inner loop.
bug or feature?
PS: tried on Ultrix 4.2, HP/UX A.B8.05 and NeXT Mach 2.2.
--
Re: odd `shift' behaviour with bash-1.12
Author: Robert Elz
Date: Sat, 29 Aug 1992 17:05
Date: Sat, 29 Aug 1992 17:05
15 lines
1112 bytes
1112 bytes
In <SPA.92Aug27153635@khore-dump.fct.unl.pt> spa@fct.unl.PT (Salvador Pinto Abreu) writes: | The scope of the `shift' command seems to be the innermost loop. For | example, the following code: Take away the "| cat" which takes the output from your inner loop, and try it then (though your output will no longer be buffered by cat). Its SOP for shells that when a control statement has I/O redirected the control statement is run in a sub-shell, and so can't affect anything in the environment of the real shell (including $# etc). Just why it has to be that way has never been clear to me, but that's the way it is. kre
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads