[SunHELP] dirname command pipe failure

Sandwich Maker adh at an.bradford.ma.us
Thu Jun 24 10:38:33 CDT 2004

" From: "Jopson, Andy" <Andrew.Jopson at Rolls-Royce.com>
" I have another one for you:
" I'm attempting to list a directory so that files can be chosen for
" processing, rather than entering as arguments. I find that the for command
" is incredibly SLOW though. Is there a faster way to list the files on
" numbered lines using another technique?
" 	count=0
" 	for file in ./*
" 	do
" 		count=`expr $count + 1`
" 		files[$count]=`basename $file`
" 		echo "	$count)	${files[count]}"
" 	done

one thing that's slowing it is that expr and basename are both cmds
that have to be forked and execed.  cpus are fast enough so it doesn't
mean so much these days, but compare


typeset -i count=0
for file in ./*
	(( count += 1 ))
	print "  $count) ${files[$count]}"

# end #

and btw ./* should be redundant; * should expand to all file names.
would simplify to

the ksh builtin 'select' may be just what you need, but i've never had
occasion to use it.



PS3="Choose from this list: "

select CHOICE in *
	print you picked file $CHOICE
Andrew Hay                                  the genius nature
internet rambler                            is to see what all have seen
adh at an.bradford.ma.us                       and think what none thought

More information about the SunHELP mailing list