v05i047: ask (quick & dirty sh version of K&P pick)
Ken Yap
ken at cs.rochester.edu
Thu Nov 10 12:07:50 AEST 1988
Posting-number: Volume 5, Issue 47
Submitted-by: "Ken Yap" <ken at cs.rochester.edu>
Archive-name: ask.sh
[Is it legal for someone to type in pick.c and post it? If so, it may be a
good idea.... ++bsa]
In a moment of need I cooked this up in a jiffy. Probably everybody has
written something like this (my friend tells me it's like pick in K+P),
but I couldn't find a similar program on my system.
An excerpt from the man page:
Ask writes its arguments one at a time on standard error, and prompts
for a reply. A response beginning with y or Y selects that argument to
be printed to standard output, anything else rejects it.
Ask is useful for interactively selecting arguments for a command from
a wildcard specification.
#!/bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #!/bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# ask.1
# ask.sh
# This archive created: Tue Nov 8 23:31:50 1988
# By: Ken Yap ()
export PATH; PATH=/bin:$PATH
echo shar: extracting "'ask.1'" '(779 characters)'
if test -f 'ask.1'
then
echo shar: over-writing existing file "'ask.1'"
fi
cat << \SHAR_EOF > 'ask.1'
.TH ASK 1 "7 November 1988"
.SH NAME
ask \- interactively select arguments
.SH SYNOPSIS
.B ask
[
.B \-s
string ]
.I argument \fB.\|.\|.\fP
.SH DESCRIPTION
.I ask
writes its arguments one at a time on standard error, and prompts
for a reply.
A response beginning with y or Y selects that argument to be printed
to standard output, anything else rejects it.
.PP
.I ask
is useful for interactively selecting arguments for a command
from a wildcard specification.
.SH OPTIONS
.IP \fB\-s\fP
The argument following is the first part of each prompt.
.SH EXAMPLE
Assume your directory contains the files a b c and d:
.PP
.nf
% cp `ask -s copy *` /dest
copy a? y
copy b?
copy c? y
copy d?
.fi
.sp
The result is that cp a c /dest is executed.
.SH AUTHOR
Ken Yap (University of Rochester)
SHAR_EOF
if test 779 -ne "`wc -c 'ask.1'`"
then
echo shar: error transmitting "'ask.1'" '(should have been 779 characters)'
fi
echo shar: extracting "'ask.sh'" '(305 characters)'
if test -f 'ask.sh'
then
echo shar: over-writing existing file "'ask.sh'"
fi
cat << \SHAR_EOF > 'ask.sh'
#!/bin/sh
# ask [ -s string ] args
# prints to stdout those args selected with a [yY]* response from user
case "x$1" in
x-s) prompt=$2; shift; shift ;;
esac
for i
do
case "x$prompt" in
x) ;;
*) 1>&2 echo -n "$prompt " ;;
esac
1>&2 echo -n "$i? "
read ans
case $ans in
y*|Y*) echo $i ;;
esac
done
SHAR_EOF
if test 305 -ne "`wc -c 'ask.sh'`"
then
echo shar: error transmitting "'ask.sh'" '(should have been 305 characters)'
fi
chmod +x 'ask.sh'
# End of shell archive
exit 0
More information about the Comp.sources.misc
mailing list