Re: how can a executing bash script be paused?



In article
<b8348de8-cc78-4b6b-8ee8-4b7d3e9ae694@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Lao Ming <laomingliu@xxxxxxxxx> wrote:

On Dec 17, 9:25 pm, Barry Margolin <bar...@xxxxxxxxxxxx> wrote:
In article
<b7812cb6-087e-48c0-8dda-e405433be...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
 Lao Ming <laoming...@xxxxxxxxx> wrote:



Is there something unusual about pausing a bash script?
I admit that I haven't done any interactive input since I started
using bash.  I want to use 'read' from stdin in order to
slow down a loop when doing:

   bash -x script

I tried:

while [ condition ] ; do
    processing ...
    printf "%s" "Pause: "
    read mypause
done

Thanks.
but it doesn't work.

It looks like it should work.  Could you be more specific than "doesn't
work"?


Well, this is the script that I am trying to debug. It's a small
script
and does only one thing. It collects the first character of each
filename
(excluding dot files) and places the char into an array (if it doesn't
exist
in the array already). The script does not produce output as it is
right now.

I don't see anything in your script that looks like the above piece that
you said doesn't work.

Do you want to put the pause inside the code that's receiving the piped
output from find|sort? It will read from the pipe, not the terminal, so
you'll need to redirect read's input from /dev/tty, as one of the other
replies suggested.


#! /bin/bash -f

check_filename()
{
filename="${FILE##*/}"
if [ "${filename:0:1}" = "." ] ; then
FLAG="true"
else
if [ "$INDEX" != "$PREVIOUS_INDEX" ] ; then
INDEX_ARRAY[$I]=$( echo "${filename:0:1}" |tr '[a-z]' '[A-
Z]' )
(( I++ ))
fi
fi
export INDEX_ARRAY
}


declare -a INDEX_ARRAY
PREVIOUS_INDEX=""
INDEX="0"
I=0
find . -type f -name "[0-z]*" |sort -f |
{
while IFS= read -r FILE ; do
FLAG="false"
INCOMPLETE=$( echo "$FILE" |sed 's/^.\///' ) # remove ^"./"
SLASH=$( echo "$INCOMPLETE" |grep '/' )
if [ "$SLASH" != "" ] ; then
dirspec="${INCOMPLETE%/*}"
#else
# check_filename
# [ "$FLAG" = "true" ] && continue
#fi
#if [ "$dirspec" != "" ] ; then
dirname="${dirspec##*/}"
if [ "$dirname" != "" ] ; then
[ "${dirname:0:1}" = "." ] && continue
else
check_filename
[ "$FLAG" = "true" ] && continue
fi
else
check_filename # new
[ "$FLAG" = "true" ] && continue # new
#filename="${FILE##*/}"
#[ "${filename:0:1}" = "." ] && continue
fi
PREVIOUS_INDEX="$INDEX"
done
echo "${INDEX_ARRAY[@]}"
}

--
Barry Margolin, barmar@xxxxxxxxxxxx
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
.



Relevant Pages

  • Re: BinaryStream.Write ByteArray erroring with Code 800A0BB9, Source ADODB.Stream
    ... script is reaching out to a SQLServer database and grabbing some data ... BinaryStream.Write method expects a byte array, ...     Else ... I made the changes to the script using your code, ...
    (microsoft.public.scripting.vbscript)
  • Re: finding files
    ... I'm back and also my script as changed ever since. ... have to be an Array then.. ... For Each strComputer In arrComputers ...     Function ReadTxtToArray ...
    (microsoft.public.scripting.vbscript)
  • Re: how can a executing bash script be paused?
    ...     processing ... ... this is the script that I am trying to debug. ... in the array already). ...
    (comp.unix.shell)
  • Re: how can a executing bash script be paused?
    ... I admit that I haven't done any interactive input since I started ...     processing ... ... in the array already). ...  The script does not produce output as it is ...
    (comp.unix.shell)
  • Re: scripting newb
    ... I was able to hobble this together from another script posted by Dan ... Dim strSearch, strAdsPath, strServerName 'from search script ...     'Prompt for search criteria ... computerName, samAccountName, givenName, sn, AdsPath ...
    (microsoft.public.scripting.vbscript)