greg - I'm sorry - I assume there is a proper place for me to post follow-up info, can you let me know where it is?
I could try for a short script, but this thing is a bit like herding eels. I narrowed it down to a single line containing 'sync' - but as you say that's clearly impossible. And to my embarrassment the bug remains unchanged when I comment-out the word sync. !!!!!!!!!!!!!!!Here is a code segment ( I have removed a few == signs so it fits across my screen. ): echo "================ At this point \$LINENO has correctly counted about 2800 lines=========================test @ 2838 $LINENO" echo "=== Something makes bash lose a few counts from \$LINENO - in this case about nine - no idea how to fix it. ===" if ! filesOrSubdirsPresent "${rootOfDummyFsToInstallAPADN}/usr/sbin/*" then : if ${G_verbose} ; then echo "Skipping ${targetAPARN} - nothing found"; fi else : echo "Installing: ${targetAPARN}*" # Do we really want the '-p' option here??? - it corrupts ownership of directories! ( cp -dpR "${rootOfDummyFsToInstallAPADN}"/usr/sbin/* ${cpDestFlag} "${targetAPARN}" ) # Not sure we can know that there are no .sh or .pl scripts already there but with execute off. # but we install so many we can't go round naming them one-by-one. # setExecutabilityOfScriptsInEntireBranch "${targetAPARN}" # All of our scripts in /usr/sbin do have .sh extensions. echo "===========================================================================================test @ +16 $LINENO" sync fi echo "==========================================================================================test @ +20 $LINENO" !!!!!!!!!!!!!!!here is the output - it is identical if I put a pound character in front of 'sync': ========================= At this point $LINENO has correctly counted about 2800 lines=========================test @ 2838 2838 === Something makes bash lose a few counts from $LINENO - in this case about nine - no idea how to fix it. === Installing: /usr/sbin/* ===============================================================================================test @ +16 2854 ===============================================================================================test @ +20 2849 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! As you can see, four lines further on, and LINENO has gone down by 5 - making it 9 too small I would fiddle around with line endings, but since it literally cogs backwards I don't think it's going to be anything simple like that. This happens again at intervals - wrong by different small numbers I think - weirdly enough the next time it happens is also near a 'sync' operation - which is what misled me. Anyway - apologies for the red herring any suggestion welcome. Do tell me if there is a proper place to put this info. On Wed, Sep 1, 2021 at 4:01 PM Greg Wooledge <g...@wooledge.org> wrote: > On Wed, Sep 01, 2021 at 10:36:21AM +0100, David Collier wrote: > > Version: > > > > GNU bash, version 5.0.3(1)-release (arm-unknown-linux-gnueabihf) > > > > Raspberry Pi using Raspbian. > > > > Installed from repo? > > > > LINENO goes backwards when run sync > > > > echo "================== At this point \$LINENO has correctly counted > about > > 2800 lines=========================test @ 2832 $LINENO" > > echo "=== Running 'sync' makes bash lose a few counts from \$LINENO - in > > this case about ten - no idea how to fix it. ===" > > sync > > echo > > > "========================================================================================test > > @ 2835 $LINENO" > > There is no plausible reason an external command (sync or any other > external command) would be able to change the value of LINENO, which is > an internal shell variable. > > Can you post a brief but complete script which demonstrates the problem? > I suspect whatever issue you're seeing is caused by something else, not > by the "sync" command. >