From: Lao Ming on
On Dec 17, 9:25 pm, Barry Margolin <bar...(a)alum.mit.edu> wrote:
> In article
> <b7812cb6-087e-48c0-8dda-e405433be...(a)q30g2000prq.googlegroups.com>,
>  Lao Ming <laoming...(a)gmail.com> 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.

#! /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[@]}"
}

From: Barry Margolin on
In article
<b8348de8-cc78-4b6b-8ee8-4b7d3e9ae694(a)w39g2000prb.googlegroups.com>,
Lao Ming <laomingliu(a)gmail.com> wrote:

> On Dec 17, 9:25�pm, Barry Margolin <bar...(a)alum.mit.edu> wrote:
> > In article
> > <b7812cb6-087e-48c0-8dda-e405433be...(a)q30g2000prq.googlegroups.com>,
> > �Lao Ming <laoming...(a)gmail.com> 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(a)alum.mit.edu
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 ***
From: Lao Ming on
On Dec 18, 9:33 pm, Barry Margolin <bar...(a)alum.mit.edu> wrote:
> In article
> <b8348de8-cc78-4b6b-8ee8-4b7d3e9ae...(a)w39g2000prb.googlegroups.com>,
>  Lao Ming <laoming...(a)gmail.com> wrote:
>
>
>
> > On Dec 17, 9:25 pm, Barry Margolin <bar...(a)alum.mit.edu> wrote:
> > > In article
> > > <b7812cb6-087e-48c0-8dda-e405433be...(a)q30g2000prq.googlegroups.com>,
> > >  Lao Ming <laoming...(a)gmail.com> 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.

Thanks, Barry. Now I understand why Chris suggested that.


> > #! /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, bar...(a)alum.mit.edu
> 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 ***