PLEX86  x86- Virtual Machine (VM) Program
 Plex86  |  CVS  |  Mailing List  |  Download  |  Linux  |  Newsgroups

urgent!!!thanks


Your Ad Here

Your Ad Here

A potentially annoying pair of newbie questions
These are likely to sound like silly questions, so please pause a moment whilst I don my asbestos long-johns...

On 2006-02-16, danish

You don't need ls, and it will fail if any directory names contain spaces.

To loop through the directories:

for i in *

When the script loops, you will be in the first subdirectory, not the directory you started in, so the other directories will not be found. See below for the solution.

To loop through all the files, use:

for j in *

If you want the first 4 characters, it makes more sense to ask for that. Use:

substr=${j:0:4}

You just buttigned $substr to $rem; why do you need to test it?

Are you sure that the destination directory exists?

for dir in *## Loop through the directories do ( ## Use a subshell, so that the loop remains in the top directory

cd "$dir" continue ## If you cannot cd into the directory ## go on to the next one

for file in * ## Loop through the files in the directory do substr=${file:0:4} ## The first four characters of the filename

destdir=..-..-..-$substr -d "$destdir" ## Check whether the destination exists mkdir "$destdir" ## If not, create it continue ## If mkdir failed, go to next file

cp "$file" "$destdir" done ) done

-- Shell Scripting Recipes: My code in this post, if any, A Problem-Solution Approach is released under the 2005, Apress GNU General Public Licence



Your Ad Here

List | Previous | Next

A potentially annoying pair of newbie questions

Linux groups from Newsgroups

The #1 Usenet Provider on the Internet

ghostscript installation differences between root or normal user