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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sequenceial directory-content acess using sh

Status
Not open for further replies.

robri

Technical User
Apr 25, 2006
2
DE
Hello,

I'd like to script the following:

As input parameter, the script recieves a source and a destination directory.

The first file (lets say the file beeing listet first if ll-ing) in the source directoy should be copied to the dest. directory. Then some other stuff is done by the script(irrelevant).
Then the next file in source directory listing should be copied to the destination directory and some other stuff is done again.
This loopes until all files in source directory have been copied.

I am not asking for the intire script here, but just a hint, how this could be solved. My main problem is to get the filenames to variables sequencially using .sh scripting-procedures. With this filenames in a loop I may simply use cp with this fienames etc.
Probably it is quite simple, but I don't get it.
Just a hint please...

Regards,
Robert
 
works!
Thanks for your really quick response feherke.
 
the script recieves a source and a destination directory
ls "$1" | while read f
do [ -f "$f" ] || continue
cp "$f" "$2"
# some other stuff here
done

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top