Re: how can a executing bash script be paused?
- From: Lao Ming <laomingliu@xxxxxxxxx>
- Date: Fri, 19 Dec 2008 08:31:33 -0800 (PST)
On Dec 18, 9:33 pm, Barry Margolin <bar...@xxxxxxxxxxxx> wrote:
In article
<b8348de8-cc78-4b6b-8ee8-4b7d3e9ae...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Lao Ming <laoming...@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.
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...@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 ***
.
- References:
- how can a executing bash script be paused?
- From: Lao Ming
- Re: how can a executing bash script be paused?
- From: Barry Margolin
- Re: how can a executing bash script be paused?
- From: Lao Ming
- Re: how can a executing bash script be paused?
- From: Barry Margolin
- how can a executing bash script be paused?
- Prev by Date: Re: Using read with variables
- Next by Date: Searching today´s date
- Previous by thread: Re: how can a executing bash script be paused?
- Next by thread: Re: how can a executing bash script be paused?
- Index(es):
Relevant Pages
|