Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unix scripting

Status
Not open for further replies.

Ultdrake

Programmer
Joined
Jul 15, 2002
Messages
19
Location
CA
I want to validate the name file by file take by the "ls" function. For exemple, I want to copy only *.htm file to an other directory... I'm searching hard... thanks a lot...
 
Hi:

I interpret you want to validate the output of the ls command a file at a time. Here's a ksh something with no error checking and the destination directory and ls hard-coded.

Careful, my readkey function returns only one character. You don't have to press enter.

Regards,

Ed


#!/bin/ksh

# this function returns only 1 character
function readkey {
local anykey oldstty

oldstty=`stty -g`
stty -icanon -echo min 1 time 0
anykey=`dd bs=1 count=1 <&0 2>/dev/null`
stty $oldstty
echo $anykey
} # end read_key


destdir=../prod
for filename in `ls *.htm`
do
echo $filename
echo &quot;copy $filename to $destdir?&quot;
anychar=$(readkey)
if [[ $anychar = 'Y' || $anychar = 'y' ]]
then
cp $filename $destdir
fi
done
 
Thanks, this code help me fine...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top