Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: Impossibilitus Interruptus ...

  1. #1
    Join Date
    Aug 2006
    Beans
    331

    Impossibilitus Interruptus ...

    I am trying to write a script which will successively show the last, second last and last, third last second last and last ... and so on ,,, lines of a file, pausing after each increment and waiting for an "Enter" (or whatever) before continuing.

    The displaying of the file content is covered by:

    count=10

    i=1

    while [ $i -le $count ]

    do

    tail -$i filename.txt

    i=`expr $i + 1`

    done

    Which seems to work just fine.

    BUT I have been unable to accomplish the pause.

    It seems that "read -p" and "pause ()" are both supposed to work. But I have been unable to get them to do so.

    Anyone have any ideas?

    Help muchly appreciated ...

  2. #2
    Join Date
    Jul 2008
    Location
    The Left Coast of the USA
    Beans
    Hidden!
    Distro
    Kubuntu

    Re: Impossibilitus Interruptus ...

    Moved to Programming Talk.

  3. #3
    Join Date
    Apr 2012
    Beans
    5,832

    Re: Impossibilitus Interruptus ...

    how about

    Code:
    i=1; while true; do read x; tail -n $((i++)) file; done

  4. #4
    Join Date
    Aug 2006
    Beans
    331

    Re: Impossibilitus Interruptus ...

    Thanks for the lightning response.

    Alas it snagged me an error message - arithmetic expression: expecting primary: "i++"

    I could pretend I knew what that meant ...

  5. #5
    Join Date
    Oct 2010
    Location
    Above ground...(for now)
    Beans
    761

    Re: Impossibilitus Interruptus ...

    In keeping with your coding style, which is much different than mine, your script worked for me when I added the blue line shown in the code box below:
    Code:
    #!/bin/bash
    set -e
    
    count=10
    i=1
    while [ $i -le $count ]
    do
    tail -$i filename.txt
    i=`expr $i + 1`
    read -p "Hit [Enter] to continue or [Ctrl+C] to abort."
    done
    I'd have done it like this:
    Code:
    #!/bin/bash
    set -e
    
    for i in {1..10}; do
      tail -$i filename.txt
      read -p "Hit [Enter] to continue or [Ctrl+C] to abort."
    done
    
    exit 0
    As you can see, steeldriver would have made it even shorter.
    Last edited by Crusty Old Fart; September 7th, 2013 at 12:31 AM.
    Suffering from severe chronic female supervision deficiency syndrome resulting in
    an increasing intolerance of adolescent scatological effluence and PMS induced nefarious diatribe.
    How to: Mark your thread as: [SOLVED]

  6. #6
    Join Date
    Apr 2012
    Beans
    5,832

    Re: Impossibilitus Interruptus ...

    Quote Originally Posted by Langstracht View Post
    Thanks for the lightning response.

    Alas it snagged me an error message - arithmetic expression: expecting primary: "i++"

    I could pretend I knew what that meant ...
    It probably means you're running it in sh (i.e. dash) rather than bash

  7. #7
    Join Date
    Aug 2006
    Beans
    331

    Re: Impossibilitus Interruptus ...

    In response to steeldriver - if you could tell me how to change that it would be most appreciated.

    In response to Crusty Old Fart - alas it does not work for me. The "Hit [Enter] to continue or [Ctrl+C] to abort." message shows up as displayed lines (albeit with the addition of ":read: 17: arg count") in between the various sections. Not a pause to be seen ,,,

  8. #8
    Join Date
    Apr 2012
    Beans
    5,832

    Re: Impossibilitus Interruptus ...

    Well the default shell is usually bash - so you must be doing something to change it to dash - either

    • you changed your default shell to /bin/sh
    • you are running this inside a shell script with a #!/bin/sh shebang at the top
    • you are explicitly invoking it via sh on the command line i.e. sh ./myscript

    If you don't do any of those things, you should get a bash shell

  9. #9
    Join Date
    Oct 2010
    Location
    Above ground...(for now)
    Beans
    761

    Re: Impossibilitus Interruptus ...

    It would be nice to see the entire content of your script in a code box. Otherwise, we're just guessing as to why what works for us isn't working for you.
    Suffering from severe chronic female supervision deficiency syndrome resulting in
    an increasing intolerance of adolescent scatological effluence and PMS induced nefarious diatribe.
    How to: Mark your thread as: [SOLVED]

  10. #10
    Join Date
    Aug 2006
    Beans
    331

    Re: Impossibilitus Interruptus ...

    In response to steeldriver - if I did any of those things it was inadvertently. Info as to how "normal service might be resumed" would be very helpful.

    In response to Crusty Old Fart - the sum total of the script was on the page. Sorry I don't see a "code box option".

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •